Skip to content

Force-close connections during HTTP/HTTPS server shutdown#468

Open
unprolix wants to merge 5 commits intomainfrom
jjb-http-connection-timeout
Open

Force-close connections during HTTP/HTTPS server shutdown#468
unprolix wants to merge 5 commits intomainfrom
jjb-http-connection-timeout

Conversation

@unprolix
Copy link
Collaborator

Summary

  • Adds graceful connection shutdown to HTTP and HTTPS wranglers, matching existing HTTP2 behavior
  • After calling closeIdleConnections(), waits up to 250ms for active connections to drain
  • Force-destroys any remaining connections after the grace period
  • Adds _prot_closeSocketsWithGracePeriod() helper method to TcpWrangler for use by subclasses

This addresses the TODO comments in HttpWrangler.js and HttpsWrangler.js about tracking connections and forcing them closed after a timeout.

Note: This PR is based on #467 (Allow Node 25) and should be merged after that PR.

Test plan

  • ubik dev lint passes
  • ubik run-tests --do=build passes (unit tests)
  • ubik run-tests --type=integration passes

Jeremy Bornstein added 2 commits January 13, 2026 05:53
Previously, HTTP and HTTPS wranglers would close idle connections
during shutdown but leave active connections to timeout naturally
(up to 3 minutes). This adds a 250ms grace period after which
remaining connections are force-destroyed, matching HTTP2 behavior.
@danfuzz
Copy link
Owner

danfuzz commented Jan 13, 2026

The main "gate" on addressing this TODO is testability. The unstated (in the code) prerequisite TODO is: Figure out a good way to do unit tests around network functionality. To be clear, the proposed change looks pretty reasonable. I just want to see a test that demonstrates that it does what it says. Thanks!

unprolix and others added 3 commits January 14, 2026 11:28
Address review feedback requesting testability for the HTTP connection
shutdown logic. Add _testing_addSocket() method to TcpWrangler to
enable injecting mock sockets for testing. Create TcpWrangler.test.js
with tests covering:
- Immediate return when no sockets present
- Early return when sockets close before grace period
- Force-destroy of lingering sockets after grace period
- Handling mix of early and late socket closures
- Skip of already-destroyed sockets
@unprolix
Copy link
Collaborator Author

Does the current state sufficiently address your concerns?

@danfuzz
Copy link
Owner

danfuzz commented Jan 16, 2026

Does the current state sufficiently address your concerns?

'Fraid not. Check out IntfTimeSource, MockTimeSource, and their use sites for how the existing system arranges for unit tests related to timing. There will probably need to be a new parameter passed into a constructor or two to get this working. (To be clear, I'm not entirely happy with this arrangement exactly because it forces the implementation to get modified in support of mocking, but it's what we've got.)

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.

2 participants