Skip to content

Commit

Permalink
http: do not abort if socket is missing
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
mcollina authored and Fishrock123 committed Jul 20, 2017
1 parent 302c19b commit 8d426bb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) {
function write_(msg, chunk, encoding, callback, fromEnd) {
if (msg.finished) {
var err = new Error('write after end');
nextTick(msg.socket[async_id_symbol],
nextTick(msg.socket && msg.socket[async_id_symbol],
writeAfterEndNT.bind(msg),
err,
callback);
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-http-server-write-after-end.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

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

// Fix for https://github.com/nodejs/node/issues/14368

const server = http.createServer(handle);

function handle(req, res) {
res.on('error', common.mustCall((err) => {
assert.strictEqual(err.message, 'write after end');
server.close();
}));

res.write('hello');
res.end();

setImmediate(common.mustCall(() => {
res.write('world');
}));
}

server.listen(0, common.mustCall(() => {
http.get(`http://localhost:${server.address().port}`);
}));

0 comments on commit 8d426bb

Please sign in to comment.