GeezerVison is showing github.com — http: don't emit error after destroy · nodejs/node@674b932
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_http_outgoing.js +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -864,6 +864,10 @@ OutgoingMessage.prototype.write = function write(chunk, encoding, callback) { |
864 | 864 | }; |
865 | 865 |
|
866 | 866 | function onError(msg, err, callback) { |
| 867 | + if (msg.destroyed) { |
| 868 | + return; |
| 869 | + } |
| 870 | + |
867 | 871 | const triggerAsyncId = msg.socket ? msg.socket[async_id_symbol] : undefined; |
868 | 872 | defaultTriggerAsyncIdScope(triggerAsyncId, |
869 | 873 | process.nextTick, |
@@ -875,7 +879,7 @@ function onError(msg, err, callback) { |
875 | 879 |
|
876 | 880 | function emitErrorNt(msg, err, callback) { |
877 | 881 | callback(err); |
878 | | - if (typeof msg.emit === 'function' && !msg._closed) { |
| 882 | + if (typeof msg.emit === 'function' && !msg.destroyed) { |
879 | 883 | msg.emit('error', err); |
880 | 884 | } |
881 | 885 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-http-outgoing-destroyed.js +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -51,5 +51,27 @@ const assert = require('assert'); |
51 | 51 | .on('error', common.mustCall()) |
52 | 52 | .write('asd'); |
53 | 53 | }); |
| 54 | +} |
54 | 55 |
|
| 56 | +{ |
| 57 | + const server = http.createServer(common.mustCall((req, res) => { |
| 58 | + assert.strictEqual(res.closed, false); |
| 59 | + res.end(); |
| 60 | + res.destroy(); |
| 61 | + // Make sure not to emit 'error' after .destroy(). |
| 62 | + res.end('asd'); |
| 63 | + assert.strictEqual(res.errored, undefined); |
| 64 | + })).listen(0, () => { |
| 65 | + http |
| 66 | + .request({ |
| 67 | + port: server.address().port, |
| 68 | + method: 'GET' |
| 69 | + }) |
| 70 | + .on('response', common.mustCall((res) => { |
| 71 | + res.resume().on('end', common.mustCall(() => { |
| 72 | + server.close(); |
| 73 | + })); |
| 74 | + })) |
| 75 | + .end(); |
| 76 | + }); |
55 | 77 | } |