From a21d5eb7e172f4aa2759cce24815027c713ef738 Mon Sep 17 00:00:00 2001 From: Sebastian Pfitzner Date: Tue, 16 Mar 2021 20:23:45 +0100 Subject: [PATCH] close channels when corresponding pipe is closed or an exception occurs --- src/core.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core.jl b/src/core.jl index a8963e2d..597d763b 100644 --- a/src/core.jl +++ b/src/core.jl @@ -106,6 +106,8 @@ function Base.run(x::JSONRPCEndpoint) else Base.display_error(stderr, err, bt) end + finally + close(x.out_msg_queue) end x.read_task = @async try @@ -143,6 +145,8 @@ function Base.run(x::JSONRPCEndpoint) else Base.display_error(stderr, err, bt) end + finally + close(x.in_msg_queue) end x.status = :running @@ -233,8 +237,8 @@ function Base.close(endpoint::JSONRPCEndpoint) flush(endpoint) endpoint.status = :closed - close(endpoint.in_msg_queue) - close(endpoint.out_msg_queue) + isopen(endpoint.in_msg_queue) && close(endpoint.in_msg_queue) + isopen(endpoint.out_msg_queue) && close(endpoint.out_msg_queue) fetch(endpoint.write_task) # TODO we would also like to close the read Task