Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/internal/streams/destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ function destroyer(stream, err) {

// TODO: Remove isRequest branches.
if (isServerRequest(stream)) {
stream._dump();
stream.socket = null;
stream.destroy(err);
} else if (isRequest(stream)) {
Expand Down
75 changes: 75 additions & 0 deletions test/parallel/test-http-server-for-await-keepalive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const http = require('http');

const agent = new http.Agent({
keepAlive: true,
maxSockets: 1,
});

let serverRequests = 0;

const server = http.createServer(async (req, res) => {
serverRequests++;

if (serverRequests === 1) {
try {
for await (const chunk of req) {
throw new Error(`payload too large: ${chunk.length}`);
}
} catch {
res.end('payload too large');
}
return;
}

res.end('ok');
});

server.listen(0, common.mustCall(() => {
const first = http.request({
port: server.address().port,
method: 'POST',
agent,
}, common.mustCall((res) => {
res.resume();

res.on('end', common.mustCall(() => {
process.nextTick(common.mustCall(() => {
const second = http.request({
port: server.address().port,
method: 'GET',
agent,
}, common.mustCall((res) => {
second.setTimeout(0);
assert.strictEqual(second.reusedSocket, true);
res.setEncoding('utf8');

let body = '';

res.on('data', (chunk) => {
body += chunk;
});

res.on('end', common.mustCall(() => {
assert.strictEqual(body, 'ok');
assert.strictEqual(serverRequests, 2);

agent.destroy();
server.close();
}));
}));

second.setTimeout(common.platformTimeout(1000), () => {
assert.fail('second keep-alive request timed out');
});

second.end();
}));
}));
}));

first.end(Buffer.alloc(1_000_000));
}));
Loading