Skip to content

Commit 2fa7d33

Browse files
mcollinalpinca
authored andcommitted
Revert "net: add support for finished after .destroy()"
This reverts commit 2da3611. PR-URL: #37964 Refs: #37937 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent 3dee233 commit 2fa7d33

File tree

4 files changed

+7
-48
lines changed

4 files changed

+7
-48
lines changed

lib/_http_incoming.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,12 @@ IncomingMessage.prototype._destroy = function _destroy(err, cb) {
181181
this.emit('aborted');
182182
}
183183

184-
// If aborted destroy socket.
185-
if (this.socket && this.aborted) {
184+
// If aborted and the underlying socket is not already destroyed,
185+
// destroy it.
186+
// We have to check if the socket is already destroyed because finished
187+
// does not call the callback when this methdod is invoked from `_http_client`
188+
// in `test/parallel/test-http-client-spurious-aborted.js`
189+
if (this.socket && !this.socket.destroyed && this.aborted) {
186190
this.socket.destroy(err);
187191
const cleanup = finished(this.socket, (e) => {
188192
cleanup();

lib/internal/streams/end-of-stream.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@ const {
2222
validateObject,
2323
} = require('internal/validators');
2424

25-
function isSocket(stream) {
26-
return (
27-
typeof stream.connect === 'function' &&
28-
typeof stream.setNoDelay === 'function' &&
29-
typeof stream.setKeepAlive === 'function'
30-
);
31-
}
32-
3325
function isRequest(stream) {
3426
return stream.setHeader && typeof stream.abort === 'function';
3527
}
@@ -105,7 +97,7 @@ function eos(stream, options, callback) {
10597
let willEmitClose = isServerResponse(stream) || (
10698
state &&
10799
state.autoDestroy &&
108-
(state.emitClose || isSocket(stream)) &&
100+
state.emitClose &&
109101
state.closed === false &&
110102
isReadable(stream) === readable &&
111103
isWritable(stream) === writable

lib/net.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,6 @@ Socket.prototype._destroy = function(exception, cb) {
662662

663663
this._handle.close(() => {
664664
debug('emit close');
665-
if (this._writableState) {
666-
this._writableState.closed = true;
667-
}
668-
if (this._readableState) {
669-
this._readableState.closed = true;
670-
}
671665
this.emit('close', isException);
672666
});
673667
this._handle.onread = noop;
@@ -1655,12 +1649,6 @@ Server.prototype._emitCloseIfDrained = function() {
16551649

16561650
function emitCloseNT(self) {
16571651
debug('SERVER: emit close');
1658-
if (self._writableState) {
1659-
self._writableState.closed = true;
1660-
}
1661-
if (self._readableState) {
1662-
self._readableState.closed = true;
1663-
}
16641652
self.emit('close');
16651653
}
16661654

test/parallel/test-net-finished.js

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)