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
  • Loading branch information
mcollina committed Jul 20, 2017
1 parent 1a49a5c commit 030344a
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 @@ -642,7 +642,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 030344a

Please sign in to comment.