diff options
author | Felix Lange <fjl@users.noreply.github.com> | 2018-10-15 16:56:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-15 16:56:04 +0800 |
commit | 2e98631c5e5724bea1a29b877929b4911bf50b86 (patch) | |
tree | e71da8eb8b99cf7f2d81249b33c8de0267685c5e /rpc/client_test.go | |
parent | 6566a0a3b82f5d24d478d3876d5fa2b1b0e8684c (diff) | |
download | dexon-2e98631c5e5724bea1a29b877929b4911bf50b86.tar dexon-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.gz dexon-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.bz2 dexon-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.lz dexon-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.xz dexon-2e98631c5e5724bea1a29b877929b4911bf50b86.tar.zst dexon-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.go | 24 |
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) { |