rpc: tighter shutdown synchronization in client subscription (#22597)
This fixes a rare issue where the client subscription forwarding loop would attempt send on the subscription's channel after Unsubscribe has returned, leading to a panic if the subscription channel was already closed by the user. Example: sub, _ := client.Subscribe(..., channel, ...) sub.Unsubscribe() close(channel) The race occurred because Unsubscribe called quitWithServer to tell the forwarding loop to stop sending on sub.channel, but did not wait for the loop to actually come down. This is fixed by adding an additional channel to track the shutdown, on which Unsubscribe now waits. Fixes #22322
This commit is contained in:
@@ -129,11 +129,15 @@ func TestClientWebsocketPing(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("client dial error: %v", err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
resultChan := make(chan int)
|
||||
sub, err := client.EthSubscribe(ctx, resultChan, "foo")
|
||||
if err != nil {
|
||||
t.Fatalf("client subscribe error: %v", err)
|
||||
}
|
||||
// Note: Unsubscribe is not called on this subscription because the mockup
|
||||
// server can't handle the request.
|
||||
|
||||
// Wait for the context's deadline to be reached before proceeding.
|
||||
// This is important for reproducing https://github.com/ethereum/go-ethereum/issues/19798
|
||||
|
Reference in New Issue
Block a user