Skip to content

Commit

Permalink
net: noop destroyed socket
Browse files Browse the repository at this point in the history
_write and _read can be called from 'connect' after
Socket.destroy() has been called. This should be a noop.

Refs: #30837
  • Loading branch information
ronag committed Dec 7, 2019
1 parent 49fb529 commit 1efb877
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ const {
ERR_SERVER_ALREADY_LISTEN,
ERR_SERVER_NOT_RUNNING,
ERR_SOCKET_BAD_PORT,
ERR_SOCKET_CLOSED
ERR_SOCKET_CLOSED,
ERR_STREAM_DESTROYED
},
errnoException,
exceptionWithHostPort,
Expand Down Expand Up @@ -571,7 +572,11 @@ Socket.prototype._read = function(n) {

if (this.connecting || !this._handle) {
debug('_read wait for connection');
this.once('connect', () => this._read(n));
this.once('connect', () => {
if (!this.destroyed) {
this._read(n)
}
});
} else if (!this._handle.reading) {
tryReadStart(this);
}
Expand Down Expand Up @@ -757,7 +762,11 @@ Socket.prototype._writeGeneric = function(writev, data, encoding, cb) {
this._pendingData = data;
this._pendingEncoding = encoding;
this.once('connect', function connect() {
this._writeGeneric(writev, data, encoding, cb);
if (this.destroyed) {
cb(new ERR_STREAM_DESTROYED('write'));
} else {
this._writeGeneric(writev, data, encoding, cb);
}
});
return;
}
Expand Down

0 comments on commit 1efb877

Please sign in to comment.