Skip to content

feat: let HTTP stop() wait for the requests in flight [draft] - #9

Merged
koresar merged 3 commits into
masterfrom
feat/graceful-http-stop
Nov 25, 2026
Merged

koresar merged 3 commits into
masterfrom
feat/graceful-http-stop

Conversation

@hmvs

@hmvs hmvs commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Today HttpTransport.stopServer() calls closeAllConnections() right after close(), so every request still running when a service gets SIGTERM loses its connection. The caller gets an error and cannot know whether the work was done. The gRPC and BullMQ transports already wait.

  • server.stop({ timeoutMs }): Node's server.close() stops new connections and lets running requests complete; closeAllConnections() runs only after timeoutMs if connections are still open.
  • A keep-alive connection whose request completes during the wait stays open until keepAliveTimeout (5s by default), so stop() can take up to that much longer than the slowest request.
  • stop() without options still closes all connections at once (now about 1 ms after close(), through the same timer), so this can ship as a minor release (2.7.0).
  • README has a short "Graceful stop" section.

server.stop({ timeoutMs }) stops accepting new connections, then waits until
no request is in flight or timeoutMs passes, and only then closes all
connections. Without timeoutMs, stop() works as before.
@hmvs hmvs changed the title feat: let HTTP stop() wait for the requests in flight feat: let HTTP stop() wait for the requests in flight [draft] Nov 25, 2026
Node's server.close() already lets the running requests complete. Instead of
counting the requests, stop() now calls closeAllConnections() only after
timeoutMs, if connections are still open.
@hmvs
hmvs marked this pull request as draft November 25, 2026 01:06
stopServer() now uses one timer for both cases: closeAllConnections() runs
after timeoutMs (0 by default) and the timer is cleared when the server has
closed. Removed two tests that did not check allserver's own behaviour.
@hmvs
hmvs marked this pull request as ready for review November 25, 2026 01:17
@koresar
koresar merged commit 0531ab4 into master Nov 25, 2026
8 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants