GWicke has uploaded a new change for review. https://gerrit.wikimedia.org/r/119442
Change subject: Improve _http_agent timeout handling ...................................................................... Improve _http_agent timeout handling * move all connect timeout related logic into a single block * call socket.emit('error', e) with an error object Change-Id: I3bd49a4b0b436bd80dbcd919d08018eb365a7635 --- M lib/_http_agent.js 1 file changed, 16 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid refs/changes/42/119442/1 diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 0989911..507ad3e 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -191,12 +191,7 @@ debug('createConnection', name, options); options.encoding = null; - var connected = false, - s = self.createConnection(options, function() { - if (this.connectTimeoutTimer) { - clearTimeout(s.connectTimeoutTimer); - } - }); + var s = self.createConnection(options); if (!self.sockets[name]) { self.sockets[name] = []; } @@ -230,12 +225,23 @@ s.on('agentRemove', onRemove); // Set up a connect timeout if connectTimeout option is set - if (options.connectTimeout && !s.connectTimeoutTimer && !connected) { + if (options.connectTimeout && !s.connectTimeoutTimer) { // Set up a timer s.connectTimeoutTimer = setTimeout(function () { - s.destroy() - //console.error('[AgentConnectTimeout]'); + var e = new Error("ETIMEDOUT") + e.code = "ETIMEDOUT" + s.end(); + s.emit("error", e) + onClose(); + //console.error('[AgentConnectTimeout ' + hostHeader + ':' + options.port + ']'); }, options.connectTimeout); + s.once('connect', function() { + if (this.connectTimeoutTimer) { + //console.log('canceled timeout'); + clearTimeout(s.connectTimeoutTimer); + this.connectTimeoutTimer = undefined; + } + }); } return s; @@ -281,5 +287,5 @@ }; exports = { - Agent: Agent + Agent: Agent }; -- To view, visit https://gerrit.wikimedia.org/r/119442 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3bd49a4b0b436bd80dbcd919d08018eb365a7635 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/parsoid Gerrit-Branch: master Gerrit-Owner: GWicke <gwi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits