Node shutdown never calls api.Service.Close, so websocket clients get 1006 instead of 1001
Maintainers usually reply within 2 days
A pull request for this has already been merged.
- #5671 by @martinconic — merged
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
Research direction
Start in pkg/node/node.go and trace how Bee.Shutdown closes b.apiCloser; compare that shutdown path with the earlier wiring described in the issue. Read api.Service.Close() and the shutdown error handling, then check the websocket handlers in pkg/api/pss.go, pkg/api/gsoc.go and pkg/api/chunk_stream.go. Done means shutdown invokes the service close before the HTTP server closes, records any returned error, and websocket clients receive code 1001.
Written by the indexing model from the issue text.
Description
Summary
On node shutdown, pkg/node never calls api.Service.Close(). Websocket clients of /pss, /gsoc and /chunks/stream are dropped when the process exits and see close code 1006, instead of the 1001 Going Away the handlers are written to send.
Cause
Bee.Shutdown closes b.apiCloser, which is the http.Server:
b.apiServer = apiServer
b.apiCloser = apiServer // pkg/node/node.go
...
tryClose(b.apiCloser, "api")
http.Server.Close and Shutdown do not track hijacked connections, so open websockets are left alone. api.Service.Close() is what closes s.quit and cancels s.bgCtx, and nothing calls it.
Before #4651 (52be59c61, "merge bee and debug APIs"), the node also set b.apiCloser = apiService, so api.Service.Close() ran on shutdown. That line was removed in #4651 and nothing replaced it.
Impact
- The
s.quitbranches inpkg/api/pss.go,pkg/api/gsoc.goandpkg/api/chunk_stream.gonever run in production, so the close frame and the clean handler exit are skipped. s.bgCtx, which bounds GSOC cache writes (pkg/api/gsoc.go), is never canceled.- Tests call
Service.Close()directly, so they pass while production takes a different path.
The process still exits and nothing hangs. Clients get an abnormal closure and no reason.
Reproduce
- Start a node and open a websocket, for example
GET /chunks/streamwithSec-WebSocket-Protocol: swarm-chunk-stream(#5618), or/pss/subscribe/{topic}. - Send SIGTERM to the node.
- The client sees
1006 (abnormal closure), not1001, and the node log has noapi shutting downline.
Observed on a Sepolia testnet full node built from #5618 (95b4acd0).
Suggested fix
Call apiService.Close() in Bee.Shutdown, before the http.Server is shut down. It closes s.quit and waits up to 1s for websocket handlers to finish, so streams get their 1001 and in-flight handlers exit. Its error (api shutting down with open websockets) should be appended to the shutdown errors like the other components.
- Dominant language
- Go
- Stars
- 1.5k
- Forks
- 390
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 24
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ethersphere/bee
-
Chequebook deployment uses a fixed 175,000 gas limit; it needs about 630,000 under Glamsterdam (live on Sepolia since 2026-10-06)Possibly taken @sbackend123 claimed this 16 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
ethersphere/bee#5650 · 1 assignee ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
ethersphere/bee#5666 ·
Maintainers usually reply within 2 days
-
Add a transaction inbox for outbound chain transactionsPossibly taken @sbackend123 claimed this 9 days ago. Openseen
Difficulty 5/5 Over a week Newbie friendliness 35/100
ethersphere/bee#5660 · 1 assignee ·
Maintainers usually reply within 2 days
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
ethersphere/bee#5659 · 6 comments ·
Maintainers usually reply within 2 days
-
accepted seen
Difficulty 4/5 3-5 days Newbie friendliness 40/100
ethersphere/bee#5648 · 1 comment ·
Maintainers usually reply within 2 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
JakeChampion/lang#13132 ·
Maintainers usually reply within 1 day
-
[BUG] deploy.restart_policy without condition drops the restart policyPossibly taken @akshat-lakhera claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
docker/compose#14383 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
Azure/azure-storage-fuse#2429 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
AvengeMedia/dank-greeter#39 · 1 comment ·
-
bug: dataplane client ignores SERVER_BASEPATH, so create/delete topic miss the subpathPossibly taken @bhataprameya claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
redpanda-data/console#2693 ·
Maintainers usually reply within 2 days