-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
http: add optional logging for socket timeouts #59514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Review requested:
|
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this PR. Instead of introducing a new env variable and a console.log, please use the debuglog and NODE_DEBUG facilities.
lib/_http_server.js
Outdated
| const serverTimeout = this.server.emit('timeout', this); | ||
|
|
||
| // Use util.debuglog for conditional logging | ||
| const debug = util.debuglog('http'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to the top of the file
| @@ -0,0 +1,14 @@ | |||
| const assert = require('assert'); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is redundant and not testing anything, you can remove it
What does this PR do?
This PR adds optional debug logging to the
socketOnTimeoutfunction inlib/_http_server.js. The logging is enabled only when the environment variableNODE_DEBUG_TIMEOUTSis set (e.g.,NODE_DEBUG_TIMEOUTS=1 node app.js). It outputs details like whether the timeout affected the request, response, or server, helping debug issues like unexpected connection drops.Example log output:
Socket timeout: req=true, res=false, server=falseThis change is non-breaking, has no performance impact in production (since it's gated by an env var), and aligns with Node.js's debuglog patterns.
Why is this useful?
_http_server.js, making it harder to trace without external tools.Changes
lib/_http_server.js: Added conditional logging insocketOnTimeout.test/parallel/test-http-timeout-logging.jsto verify logging under forced timeouts.Diff summary (full diff in commits):
Testing
make teston [your OS, e.g., Ubuntu 22.04] – all tests pass.NODE_DEBUG_TIMEOUTSis set, and timeouts are triggered correctly.benchmark/http/simple.js– performance unchanged).References
I signed the CLA. Let me know if any adjustments are needed!