From 21b34ba1334a359126e9fff95706433ae9b486cf Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 11 Mar 2020 19:14:49 +0100 Subject: [PATCH] Fix chan handling Signed-off-by: Jakub Sztandera --- lib/jsonrpc/handler.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/jsonrpc/handler.go b/lib/jsonrpc/handler.go index bca1bdf78..29e8af1cc 100644 --- a/lib/jsonrpc/handler.go +++ b/lib/jsonrpc/handler.go @@ -230,7 +230,13 @@ func (h handlers) handle(ctx context.Context, req request, w func(func(io.Writer } } } - if resp.Result != nil && reflect.TypeOf(resp.Result).Kind() == reflect.Chan { + + var res interface{} + if handler.valOut != -1 { + res = callResult[handler.valOut].Interface() + } + + if res != nil && reflect.TypeOf(res).Kind() == reflect.Chan { // Channel responses are sent from channel control goroutine. // Sending responses here could cause deadlocks on writeLk, or allow // sending channel messages before this rpc call returns @@ -250,8 +256,8 @@ func (h handlers) handle(ctx context.Context, req request, w func(func(io.Writer } // check error as JSON-RPC spec prohibits error and value at the same time - if resp.Error == nil && handler.valOut != -1 { - resp.Result = callResult[handler.valOut].Interface() + if resp.Error == nil { + resp.Result = res } w(func(w io.Writer) {