Skip to content

Commit 8d426bb

Browse files
mcollinaFishrock123
authored andcommitted
http: do not abort if socket is missing
Fixes: #14368 PR-URL: #14387 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent 302c19b commit 8d426bb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

lib/_http_outgoing.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
633633
function write_(msg, chunk, encoding, callback, fromEnd) {
634634
if (msg.finished) {
635635
var err = new Error('write after end');
636-
nextTick(msg.socket[async_id_symbol],
636+
nextTick(msg.socket && msg.socket[async_id_symbol],
637637
writeAfterEndNT.bind(msg),
638638
err,
639639
callback);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const http = require('http');
5+
const assert = require('assert');
6+
7+
// Fix for https://github.com/nodejs/node/issues/14368
8+
9+
const server = http.createServer(handle);
10+
11+
function handle(req, res) {
12+
res.on('error', common.mustCall((err) => {
13+
assert.strictEqual(err.message, 'write after end');
14+
server.close();
15+
}));
16+
17+
res.write('hello');
18+
res.end();
19+
20+
setImmediate(common.mustCall(() => {
21+
res.write('world');
22+
}));
23+
}
24+
25+
server.listen(0, common.mustCall(() => {
26+
http.get(`http://localhost:${server.address().port}`);
27+
}));

0 commit comments

Comments
 (0)