Skip to content

[fix] Stop a silent admin connection from stalling shutdown - #15

Merged
ok merged 1 commit into
mainfrom
ok/shutdown-idle-sockets
Sep 20, 2026
Merged

ok merged 1 commit into
mainfrom
ok/shutdown-idle-sockets

Conversation

@ok

@ok ok commented Sep 20, 2026

Copy link
Copy Markdown
Owner

The bug

On a live StartOS box every stop of the relay logged shutdown timed out — exiting and the process exited 1 after exactly 15 seconds.

admin.close() was server.close(resolve), which waits for every open socket. Node's idle-connection sweep only covers sockets that have completed a request, so a connection that was opened and never used — which browsers and platform proxies create speculatively all the time — held the close open until the shutdown timer fired. stopRelay awaits the admin server first, so the DHT node was never closed cleanly either.

Reproduced against a real process: with one silent TCP connection to the admin port, SIGTERM exited 1 after 15005 ms. A keep-alive connection that had sent a request did not reproduce it.

The fix

Call server.closeAllConnections() right after server.close(). At shutdown there is nothing on the read-only admin surface worth waiting for.

With the fix the same reproduction exits 0 in about 270 ms.

Testing

  • New integration test in admin-http.test.js, red before the fix: opens a silent socket, waits until the server has accepted it, and asserts stop() completes. It races a timer so a regression is an assertion, not a hung suite.
  • npm run lint clean, npm test 402/402.
  • Lesson added to .claude/lessons.md.

server.close() waits for every open socket, and one that connected
without ever sending a request is not idle to Node, so a browser's
speculative connection made every stop take the full 15s timeout and
exit 1. Close all admin connections once the server stops listening.
@ok
ok merged commit 5f14d69 into main Sep 20, 2026
4 checks passed
@ok
ok deleted the ok/shutdown-idle-sockets branch September 20, 2026 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant