Skip to content

Commit

Permalink
lib: add handling of EAGAIN error on connection
Browse files Browse the repository at this point in the history
PR-URL: #281
Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com>
Reviewed-By: Dmytro Nechai <nechaido@gmail.com>
Reviewed-By: Denys Otrishko <shishugi@gmail.com>
  • Loading branch information
belochub committed Jul 31, 2017
1 parent 9116125 commit d5b6eaf
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,23 @@ class Transport extends EventEmitter {
}
}

const socketFactory = connect => (...options) => {
const callback = common.extractCallback(options);
const socket = connect(...options);
socket.once('error', callback);
socket.once('connect', () => {
socket.removeListener('error', callback);
callback(null, socket);
});
const socketFactory = (connect) => {
const resultConnectFn = (...options) => {
const callback = common.extractCallback(options);
const socket = connect(...options);
socket.once('error', (error) => {
if (error.code !== 'EAGAIN') {
callback(error);
return;
}
process.nextTick(resultConnectFn, ...options, callback);
});
socket.once('connect', () => {
socket.removeListener('error', callback);
callback(null, socket);
});
};
return resultConnectFn;
};

// Create a function that will be bound to socketFactory that will
Expand Down

0 comments on commit d5b6eaf

Please sign in to comment.