Skip to content

Commit

Permalink
fixup: pass test
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Sep 23, 2019
1 parent efa5cbb commit 55d1d3d
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions lib/_http_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,6 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
// client
function responseKeepAlive(req) {
const socket = req.socket;
const res = req.res;

req.emit('close');
if (res) {
res.emit('close');
}

debug('AGENT socket keep-alive');
if (req.timeoutCb) {
Expand All @@ -613,7 +607,7 @@ function responseKeepAlive(req) {
const asyncId = socket._handle ? socket._handle.getAsyncId() : undefined;
// Mark this socket as available, AFTER user-added end
// handlers have a chance to run.
defaultTriggerAsyncIdScope(asyncId, process.nextTick, emitFreeNT, socket);
defaultTriggerAsyncIdScope(asyncId, process.nextTick, emitFreeNT, req);
}

function responseOnEnd() {
Expand All @@ -635,33 +629,32 @@ function responseOnEnd() {
socket.end();
}
assert(!socket.writable);
} else if (req.finished) {
} else if (req.finished && !this.aborted) {
// We can assume `req.finished` means all data has been written since:
// - `'responseOnEnd'` means we have been assigned a socket.
// - when we have a socket we write directly to it without buffering.
// - `req.finished` means `end()` has been called and no further data.
// can be written

// Run in next tick so any pending handlers
// have a chance to run first and perform any
// modifications.
process.nextTick(responseKeepAlive, req);
responseKeepAlive(req);
}
}

function requestOnPrefinish() {
const req = this;

if (req.shouldKeepAlive && req._ended) {
// Run in next tick so any pending handlers
// have a chance to run first and perform any
// modifications.
process.nextTick(responseKeepAlive, req);
}
if (req.shouldKeepAlive && req._ended)
responseKeepAlive(req);
}

function emitFreeNT(socket) {
socket.emit('free');
function emitFreeNT(req) {
req.emit('close');
if (req.res) {
req.res.emit('close');
}

if (req.socket) {
req.socket.emit('free');
}
}

function tickOnSocket(req, socket) {
Expand Down

0 comments on commit 55d1d3d

Please sign in to comment.