rpc: fix client shutdown hang when Close races with Unsubscribe (#17894)

Fixes #17837
This commit is contained in:
Felix Lange
2018-10-15 10:56:04 +02:00
committed by GitHub
parent 6566a0a3b8
commit 2e98631c5e
3 changed files with 102 additions and 47 deletions

View File

@ -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) {