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 committed by Anna Shaleva
parent ab64f7cfe4
commit 08b273266b

View file

@ -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
}