Skip to content

Commit

Permalink
rpcclient/WS: do not deadlock on connection loss
Browse files Browse the repository at this point in the history
`makeWsRequest` creates a channel for response and waits for it. If between
creating the channel and starting the reading `select` connection is lost
(`writerDone` channel is closed), nothing reads from the channel and a
deadlock appears. Looking at "done" channels when transferring RPC data
solves the issue. Closes #3530.

Signed-off-by: Pavel Karpy <[email protected]>
  • Loading branch information
carpawell committed Jul 29, 2024
1 parent 8d4e8b6 commit 9fadfef
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/rpcclient/wsclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,13 @@ readloop:
connCloseErr = fmt.Errorf("unknown response channel for response %d", id)
break readloop // Unknown response (unexpected response ID).
}
ch <- &rr.Response
select {
case <-c.writerDone:
break readloop
case <-c.shutdown:
break readloop

Check warning on line 608 in pkg/rpcclient/wsclient.go

View check run for this annotation

Codecov / codecov/patch

pkg/rpcclient/wsclient.go#L605-L608

Added lines #L605 - L608 were not covered by tests
case ch <- &rr.Response:
}
} else {
// Malformed response, neither valid request, nor valid response.
connCloseErr = fmt.Errorf("malformed response")
Expand Down

0 comments on commit 9fadfef

Please sign in to comment.