| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ccd900f commit c784f15
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -430,13 +430,25 @@ function socketCloseListener() { | |||
| 430 | 430 | req.destroyed = true; | |
| 431 | 431 | if (res) { | |
| 432 | 432 | // Socket closed before we emitted 'end' below. | |
| 433 | + // TOOD(ronag): res.destroy(err) | ||
| 433 | 434 | if (!res.complete) { | |
| 434 | - res.destroy(connResetException('aborted')); | ||
| 435 | + res.aborted = true; | ||
| 436 | + res.emit('aborted'); | ||
| 437 | + if (res.listenerCount('error') > 0) { | ||
| 438 | + res.emit('error', connResetException('aborted')); | ||
| 439 | + } | ||
| 435 | 440 | } | |
| 436 | 441 | req._closed = true; | |
| 437 | 442 | req.emit('close'); | |
| 438 | 443 | if (!res.aborted && res.readable) { | |
| 444 | + res.on('end', function() { | ||
| 445 | + this.destroyed = true; | ||
| 446 | + this.emit('close'); | ||
| 447 | + }); | ||
| 439 | 448 | res.push(null); | |
| 449 | + } else { | ||
| 450 | + res.destroyed = true; | ||
| 451 | + res.emit('close'); | ||
| 440 | 452 | } | |
| 441 | 453 | } else { | |
| 442 | 454 | if (!req.socket._hadError) { | |
@@ -685,6 +697,7 @@ function responseKeepAlive(req) { | |||
| 685 | 697 | ||
| 686 | 698 | req.destroyed = true; | |
| 687 | 699 | if (req.res) { | |
| 700 | + req.res.destroyed = true; | ||
| 688 | 701 | // Detach socket from IncomingMessage to avoid destroying the freed | |
| 689 | 702 | // socket in IncomingMessage.destroy(). | |
| 690 | 703 | req.res.socket = null; | |
@@ -739,6 +752,10 @@ function requestOnPrefinish() { | |||
| 739 | 752 | function emitFreeNT(req) { | |
| 740 | 753 | req._closed = true; | |
| 741 | 754 | req.emit('close'); | |
| 755 | + if (req.res) { | ||
| 756 | + req.res.emit('close'); | ||
| 757 | + } | ||
| 758 | + | ||
| 742 | 759 | if (req.socket) { | |
| 743 | 760 | req.socket.emit('free'); | |
| 744 | 761 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ const { | |||
| 27 | 27 | Symbol | |
| 28 | 28 | } = primordials; | |
| 29 | 29 | ||
| 30 | - const { Readable, finished } = require('stream'); | ||
| 30 | + const Stream = require('stream'); | ||
| 31 | 31 | ||
| 32 | 32 | const kHeaders = Symbol('kHeaders'); | |
| 33 | 33 | const kHeadersCount = Symbol('kHeadersCount'); | |
@@ -54,7 +54,7 @@ function IncomingMessage(socket) { | |||
| 54 | 54 | }; | |
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | - Readable.call(this, streamOptions); | ||
| 57 | + Stream.Readable.call(this, { autoDestroy: false, ...streamOptions }); | ||
| 58 | 58 | ||
| 59 | 59 | this._readableState.readingMore = true; | |
| 60 | 60 | ||
@@ -89,8 +89,8 @@ function IncomingMessage(socket) { | |||
| 89 | 89 | // read by the user, so there's no point continuing to handle it. | |
| 90 | 90 | this._dumped = false; | |
| 91 | 91 | } | |
| 92 | - ObjectSetPrototypeOf(IncomingMessage.prototype, Readable.prototype); | ||
| 93 | - ObjectSetPrototypeOf(IncomingMessage, Readable); | ||
| 92 | + ObjectSetPrototypeOf(IncomingMessage.prototype, Stream.Readable.prototype); | ||
| 93 | + ObjectSetPrototypeOf(IncomingMessage, Stream.Readable); | ||
| 94 | 94 | ||
| 95 | 95 | ObjectDefineProperty(IncomingMessage.prototype, 'connection', { | |
| 96 | 96 | get: function() { | |
@@ -160,31 +160,19 @@ IncomingMessage.prototype._read = function _read(n) { | |||
| 160 | 160 | readStart(this.socket); | |
| 161 | 161 | }; | |
| 162 | 162 | ||
| 163 | + | ||
| 163 | 164 | // It's possible that the socket will be destroyed, and removed from | |
| 164 | 165 | // any messages, before ever calling this. In that case, just skip | |
| 165 | 166 | // it, since something else is destroying this connection anyway. | |
| 166 | - IncomingMessage.prototype._destroy = function _destroy(err, cb) { | ||
| 167 | - if (!this.readableEnded || !this.complete) { | ||
| 168 | - this.aborted = true; | ||
| 169 | - this.emit('aborted'); | ||
| 170 | - } | ||
| 171 | - | ||
| 172 | - // If aborted and the underlying socket is not already destroyed, | ||
| 173 | - // destroy it. | ||
| 174 | - // We have to check if the socket is already destroyed because finished | ||
| 175 | - // does not call the callback when this methdod is invoked from `_http_client` | ||
| 176 | - // in `test/parallel/test-http-client-spurious-aborted.js` | ||
| 177 | - if (this.socket && !this.socket.destroyed && this.aborted) { | ||
| 178 | - this.socket.destroy(err); | ||
| 179 | - const cleanup = finished(this.socket, (e) => { | ||
| 180 | - cleanup(); | ||
| 181 | - onError(this, e || err, cb); | ||
| 182 | - }); | ||
| 183 | - } else { | ||
| 184 | - onError(this, err, cb); | ||
| 185 | - } | ||
| 167 | + IncomingMessage.prototype.destroy = function destroy(error) { | ||
| 168 | + // TODO(ronag): Implement in terms of _destroy | ||
| 169 | + this.destroyed = true; | ||
| 170 | + if (this.socket) | ||
| 171 | + this.socket.destroy(error); | ||
| 172 | + return this; | ||
| 186 | 173 | }; | |
| 187 | 174 | ||
| 175 | + | ||
| 188 | 176 | IncomingMessage.prototype._addHeaderLines = _addHeaderLines; | |
| 189 | 177 | function _addHeaderLines(headers, n) { | |
| 190 | 178 | if (headers && headers.length) { | |
@@ -361,16 +349,6 @@ IncomingMessage.prototype._dump = function _dump() { | |||
| 361 | 349 | } | |
| 362 | 350 | }; | |
| 363 | 351 | ||
| 364 | - function onError(self, error, cb) { | ||
| 365 | - // This is to keep backward compatible behavior. | ||
| 366 | - // An error is emitted only if there are listeners attached to the event. | ||
| 367 | - if (self.listenerCount('error') === 0) { | ||
| 368 | - cb(); | ||
| 369 | - } else { | ||
| 370 | - cb(error); | ||
| 371 | - } | ||
| 372 | - } | ||
| 373 | - | ||
| 374 | 352 | module.exports = { | |
| 375 | 353 | IncomingMessage, | |
| 376 | 354 | readStart, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -575,7 +575,14 @@ function socketOnClose(socket, state) { | |||
| 575 | 575 | function abortIncoming(incoming) { | |
| 576 | 576 | while (incoming.length) { | |
| 577 | 577 | const req = incoming.shift(); | |
| 578 | - req.destroy(connResetException('aborted')); | ||
| 578 | + // TODO(ronag): req.destroy(err) | ||
| 579 | + req.aborted = true; | ||
| 580 | + req.destroyed = true; | ||
| 581 | + req.emit('aborted'); | ||
| 582 | + if (req.listenerCount('error') > 0) { | ||
| 583 | + req.emit('error', connResetException('aborted')); | ||
| 584 | + } | ||
| 585 | + req.emit('close'); | ||
| 579 | 586 | } | |
| 580 | 587 | // Abort socket._httpMessage ? | |
| 581 | 588 | } | |
@@ -734,9 +741,14 @@ function clearIncoming(req) { | |||
| 734 | 741 | if (parser && parser.incoming === req) { | |
| 735 | 742 | if (req.readableEnded) { | |
| 736 | 743 | parser.incoming = null; | |
| 744 | + req.destroyed = true; | ||
| 745 | + req.emit('close'); | ||
| 737 | 746 | } else { | |
| 738 | 747 | req.on('end', clearIncoming); | |
| 739 | 748 | } | |
| 749 | + } else { | ||
| 750 | + req.destroyed = true; | ||
| 751 | + req.emit('close'); | ||
| 740 | 752 | } | |
| 741 | 753 | } | |
| 742 | 754 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments