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 <roman@nspcc.ru>
This commit is contained in:
Roman Khimov 2023-04-18 19:34:38 +03:00
parent a4cc6da766
commit 45b353781f

View file

@ -638,7 +638,10 @@ func (c *WSClient) makeWsRequest(r *neorpc.Request) (*neorpc.Response, error) {
select { select {
case <-c.done: case <-c.done:
return nil, errors.New("connection lost while waiting for the response") 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) c.unregisterRespChannel(r.ID)
return resp, nil return resp, nil
} }