go-ethereum/rpc
Daniel Liu 9f504a6243
rpc: tighter shutdown synchronization in client subscription #22597 (#955)
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

Co-authored-by: Felix Lange <fjl@twurst.com>
2025-04-24 18:17:45 +08:00
..
testdata upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
client.go rpc: fix staticcheck warning SA1029 by add PeerInfo (#24255) 2024-10-25 12:32:13 +08:00
client_example_test.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
client_test.go rpc: tighter shutdown synchronization in client subscription #22597 (#955) 2025-04-24 18:17:45 +08:00
constants_unix.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
constants_unix_nocgo.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
doc.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
endpoints.go console: handle eth.coinbase throws #19374 (#953) 2025-04-24 18:11:48 +08:00
errors.go rpc: add HTTPError type for HTTP error responses #22677 (#956) 2025-04-22 15:16:48 +08:00
handler.go rpc: tighter shutdown synchronization in client subscription #22597 (#955) 2025-04-24 18:17:45 +08:00
http.go rpc: add HTTPError type for HTTP error responses #22677 (#956) 2025-04-22 15:16:48 +08:00
http_test.go rpc: add HTTPError type for HTTP error responses #22677 (#956) 2025-04-22 15:16:48 +08:00
inproc.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
ipc.go rpc: clean up IPC handler (#16524) 2024-11-04 12:31:15 +08:00
ipc_js.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
ipc_unix.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
ipc_wasip1.go all: add build tags for wasip1 (#31090) 2025-03-19 18:02:46 +08:00
ipc_windows.go console: handle eth.coinbase throws #19374 (#953) 2025-04-24 18:11:48 +08:00
json.go rpc: fix staticcheck warning SA1029 by add PeerInfo (#24255) 2024-10-25 12:32:13 +08:00
metrics.go rpc: fix ns/µs mismatch in metrics (#28649) 2024-12-13 14:00:13 +08:00
server.go all: use github.com/deckarep/golang-set/v2 (generic set) (#26159) 2025-01-24 16:54:11 +08:00
server_test.go rpc: fix staticcheck warning SA1029 by add PeerInfo (#24255) 2024-10-25 12:32:13 +08:00
service.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
stdio.go upgrade the websocket in xdpos (#349) 2023-11-06 15:37:14 +11:00
subscription.go rpc: tighter shutdown synchronization in client subscription #22597 (#955) 2025-04-24 18:17:45 +08:00
subscription_test.go console: handle eth.coinbase throws #19374 (#953) 2025-04-24 18:11:48 +08:00
testservice_test.go rpc: fix staticcheck warning SA1029 by add PeerInfo (#24255) 2024-10-25 12:32:13 +08:00
types.go rpc: add HTTPError type for HTTP error responses #22677 (#956) 2025-04-22 15:16:48 +08:00
types_test.go all: get rid of custom MaxUint64 and MaxUint64 (#30636) 2024-12-28 09:06:31 +08:00
websocket.go all: use github.com/deckarep/golang-set/v2 (generic set) (#26159) 2025-01-24 16:54:11 +08:00
websocket_test.go rpc: tighter shutdown synchronization in client subscription #22597 (#955) 2025-04-24 18:17:45 +08:00