aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/client_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@users.noreply.github.com>2018-10-15 16:56:04 +0800
committerGitHub <noreply@github.com>2018-10-15 16:56:04 +0800
commit2e98631c5e5724bea1a29b877929b4911bf50b86 (patch)
treee71da8eb8b99cf7f2d81249b33c8de0267685c5e /rpc/client_test.go
parent6566a0a3b82f5d24d478d3876d5fa2b1b0e8684c (diff)
downloadgo-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.gz
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.bz2
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.lz
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.xz
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.zst
go-tangerine-2e98631c5e5724bea1a29b877929b4911bf50b86.zip
rpc: fix client shutdown hang when Close races with Unsubscribe (#17894)
Fixes #17837
Diffstat (limited to 'rpc/client_test.go')
-rw-r--r--rpc/client_test.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/rpc/client_test.go b/rpc/client_test.go
index 4f354d389..a8195c0af 100644
--- a/rpc/client_test.go
+++ b/rpc/client_test.go
@@ -323,6 +323,30 @@ func TestClientSubscribeClose(t *testing.T) {
}
}
+// This test reproduces https://github.com/ethereum/go-ethereum/issues/17837 where the
+// client hangs during shutdown when Unsubscribe races with Client.Close.
+func TestClientCloseUnsubscribeRace(t *testing.T) {
+ service := &NotificationTestService{}
+ server := newTestServer("eth", service)
+ defer server.Stop()
+
+ for i := 0; i < 20; i++ {
+ client := DialInProc(server)
+ nc := make(chan int)
+ sub, err := client.EthSubscribe(context.Background(), nc, "someSubscription", 3, 1)
+ if err != nil {
+ t.Fatal(err)
+ }
+ go client.Close()
+ go sub.Unsubscribe()
+ select {
+ case <-sub.Err():
+ case <-time.After(5 * time.Second):
+ t.Fatal("subscription not closed within timeout")
+ }
+ }
+}
+
// This test checks that Client doesn't lock up when a single subscriber
// doesn't read subscription events.
func TestClientNotificationStorm(t *testing.T) {