Skip to content

Commit 96a0377

Browse files
committed
http: recheck current socket before emitting drain
Read the current socket after the coalesced write callbacks run, since uncork() may initially buffer data before a socket is assigned. Check that the current socket exists and is not destroyed before emitting drain. Refs: #66782 (comment) Assisted-by: AI coding agent Signed-off-by: junyup0503 <[email protected]>
1 parent a360243 commit 96a0377

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎lib/internal/http/outgoing.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,9 @@ OutgoingMessage.prototype.uncork = function uncork() {
380380
// chunks, but net.Socket counts string chunks in UTF-16 code units and
381381
// may stay below its own highWaterMark, so it never emits 'drain'.
382382
// Re-check once the flushed data has been written.
383-
if (!err && this.writableNeedDrain && !socket.destroyed &&
384-
this.writableLength === 0) {
383+
const currentSocket = this[kSocket];
384+
if (!err && this.writableNeedDrain && currentSocket &&
385+
!currentSocket.destroyed && this.writableLength === 0) {
385386
this[kNeedDrain] = false;
386387
this.emit('drain');
387388
}

0 commit comments

Comments
 (0)