[#XX] rpcclient: Fix ws-reader hang on sending a response
* `wsReader` may get blocked on sending to the response channel if receiver can't read the response out. * If `wsWriter` goroutine got an error or `wsClient` is going to get shut down, then `wsReader` should stop trying to send the response as it's not reasonable and this leads only to blocking. Signed-off-by: Airat Arifullin <a.arifullin@yadro.com>
This commit is contained in:
parent
594f716b3d
commit
10c8492276
1 changed files with 9 additions and 1 deletions
|
@ -601,7 +601,15 @@ readloop:
|
||||||
connCloseErr = fmt.Errorf("unknown response channel for response %d", id)
|
connCloseErr = fmt.Errorf("unknown response channel for response %d", id)
|
||||||
break readloop // Unknown response (unexpected response ID).
|
break readloop // Unknown response (unexpected response ID).
|
||||||
}
|
}
|
||||||
ch <- &rr.Response
|
select {
|
||||||
|
case <-c.writerDone:
|
||||||
|
connCloseErr = fmt.Errorf("response won't be sent to channel %d: ws-writer is done", id)
|
||||||
|
break readloop
|
||||||
|
case <-c.shutdown:
|
||||||
|
connCloseErr = fmt.Errorf("response won't be sent to channel %d: shutting down", id)
|
||||||
|
break readloop
|
||||||
|
case ch <- &rr.Response:
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Malformed response, neither valid request, nor valid response.
|
// Malformed response, neither valid request, nor valid response.
|
||||||
connCloseErr = fmt.Errorf("malformed response")
|
connCloseErr = fmt.Errorf("malformed response")
|
||||||
|
|
Loading…
Reference in a new issue