Skip to content

Commit

Permalink
fix: add guard for socket presence
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 8, 2019
2 parents 0fe8eb0 + 66f01c5 commit e92fb8a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/classes/Agent.js
Expand Up @@ -123,13 +123,15 @@ class Agent {
// $FlowFixMe It appears that Flow is missing the method description.
this.createConnection(connectionConfiguration, (error, socket) => {
// @see https://github.com/nodejs/node/issues/5757#issuecomment-305969057
socket.setTimeout(this.socketConnectionTimeout, () => {
socket.destroy();
});
if (socket) {
socket.setTimeout(this.socketConnectionTimeout, () => {
socket.destroy();
});

socket.once('connect', () => {
socket.setTimeout(0);
});
socket.once('connect', () => {
socket.setTimeout(0);
});
}

if (error) {
request.emit('error', error);
Expand Down

0 comments on commit e92fb8a

Please sign in to comment.