From 45b353781f417b6798c48ad3b1ffcd44c31f63fb Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 18 Apr 2023 19:34:38 +0300 Subject: [PATCH] rpcclient: correctly handle request channel closure wsReader() closes c.done first and then goes over the list of c.respChannels. Technically this means that any of the two can be taken in this select. Signed-off-by: Roman Khimov --- pkg/rpcclient/wsclient.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/rpcclient/wsclient.go b/pkg/rpcclient/wsclient.go index c3f6172a1..ff1e21bd1 100644 --- a/pkg/rpcclient/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -638,7 +638,10 @@ func (c *WSClient) makeWsRequest(r *neorpc.Request) (*neorpc.Response, error) { select { case <-c.done: return nil, errors.New("connection lost while waiting for the response") - case resp := <-ch: + case resp, ok := <-ch: + if !ok { + return nil, errors.New("connection lost while waiting for the response") + } c.unregisterRespChannel(r.ID) return resp, nil }