From 5481339d6928773ea6ba19e99b2f9c32e315011e Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Fri, 26 Jul 2024 11:11:12 +0300 Subject: [PATCH] [#1] 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 --- pkg/rpcclient/wsclient.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/rpcclient/wsclient.go b/pkg/rpcclient/wsclient.go index dc877c407..455e4d4f8 100644 --- a/pkg/rpcclient/wsclient.go +++ b/pkg/rpcclient/wsclient.go @@ -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 + case ch <- &rr.Response: + } } else { // Malformed response, neither valid request, nor valid response. connCloseErr = fmt.Errorf("malformed response")