GeezerVison is showing github.com — http: fast-forward teardown of unread messages · nodejs/node@e3cc0d9
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_incoming.js +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -292,6 +292,13 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) { |
292 | 292 | cleanup(); |
293 | 293 | process.nextTick(onError, this, e || err, cb); |
294 | 294 | }); |
| 295 | + } else if (err == null && !this.aborted) { |
| 296 | + // The message was received completely and is being destroyed cleanly: |
| 297 | + // complete the destroy synchronously. 'close' is still emitted on a |
| 298 | + // later tick by the stream machinery. The deferral below only exists |
| 299 | + // so that 'error' listeners attached right after destroy(err) still |
| 300 | + // receive the error, which cannot matter when there is no error. |
| 301 | + cb(); |
295 | 302 | } else { |
296 | 303 | process.nextTick(onError, this, err, cb); |
297 | 304 | } |
@@ -505,7 +512,14 @@ IncomingMessage.prototype._dump = function _dump() { |
505 | 512 | // If there is buffered data, it may trigger 'data' events. |
506 | 513 | // Remove 'data' event listeners explicitly. |
507 | 514 | this.removeAllListeners('data'); |
508 | | - this.resume(); |
| 515 | + if (this.complete && !this.destroyed && this.readableLength === 0) { |
| 516 | + // The message was fully received and never read: there is nothing to |
| 517 | + // pull off the wire. Go straight to the 'end' emission instead of |
| 518 | + // paying for the resume() and flow() scheduling machinery. |
| 519 | + this.read(0); |
| 520 | + } else { |
| 521 | + this.resume(); |
| 522 | + } |
509 | 523 | } |
510 | 524 | }; |
511 | 525 |
|
|