Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
avwo committed Jul 31, 2017
1 parent 4fbfd9a commit 11838ea
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,40 @@ exports.getDataDir = getDataDir;
try {
var async_id_symbol = process.binding('async_wrap').async_id_symbol;
} catch (e) {}
var emptyHandle = {
asyncReset: noop,
getAsyncId: noop
};
function createAgent(agentConfig, https) {
var agent = new (https ? httpsAgent : httpAgent)(agentConfig);
if (async_id_symbol) {
var addRequest = agent.addRequest;
agent.addRequest = function(req) {
agent.addRequest = function(req, options) {
var freeSockets = this.freeSockets[this.getName(options)];
var mockAsyncReset;
if (freeSockets && freeSockets.length) {
var socket = freeSockets[0];
var handle = socket._handle;
if (!handle) {
socket._handle = emptyHandle;
mockAsyncReset = true;
} else if (typeof handle.asyncReset !== 'function') {
handle.asyncReset = noop;
mockAsyncReset = true;
}
}
var onSocket = req.onSocket;
req.onSocket = function(socket) {
try {
socket[async_id_symbol] = socket._handle.getAsyncId();
} catch(e) {}
if ( mockAsyncReset) {
if (socket._handle === emptyHandle) {
delete socket._handle;
} else if (socket._handle.asyncReset === noop) {
delete socket._handle.asyncReset;
}
}
onSocket.apply(this, arguments);
};
addRequest.apply(this, arguments);
Expand Down

0 comments on commit 11838ea

Please sign in to comment.