Skip to content
Prev Previous commit
Next Next commit
http: add optional logging for socket timeouts
  • Loading branch information
rohit-chouhan authored Aug 18, 2025
commit 7d974bf2781e803bc3bc992d0f7cfa3e035cd559
8 changes: 4 additions & 4 deletions lib/_http_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const {
const net = require('net');
const EE = require('events');
const assert = require('internal/assert');
const util = require('internal/util');
const {
parsers,
freeParser,
Expand Down Expand Up @@ -811,10 +812,9 @@ function socketOnTimeout() {
const resTimeout = res && res.emit('timeout', this);
const serverTimeout = this.server.emit('timeout', this);

// Suggested addition: Optional debug logging
if (process.env.NODE_DEBUG_TIMEOUTS) {
console.log(`Socket timeout: req=${!!req}, res=${!!res}, server=${!!serverTimeout}`);
}
// Use util.debuglog for conditional logging
const debug = util.debuglog('http');
Copy link
Member

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

debug('Socket timeout: req=%s, res=%s, server=%s', !!req, !!res, !!serverTimeout);

if (!reqTimeout && !resTimeout && !serverTimeout)
this.destroy();
Expand Down