diff --git a/.travis.yml b/.travis.yml index 3669bc7..b722f48 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,9 @@ node_js: - "0.10" - "0.8" - iojs + - "4" + - "6" + - stable script: "npm test" sudo: false before_install: diff --git a/lib/request.js b/lib/request.js index 567fc8d..b7429c1 100644 --- a/lib/request.js +++ b/lib/request.js @@ -92,7 +92,16 @@ function regRequest (uri, params, cb_) { } function makeRequest (uri, params, cb_) { - var cb = once(cb_) + var socket + var cb = once(function (er, parsed, raw, response) { + if (socket) { + // The socket might be returned to a pool for re-use, so don’t keep + // the 'error' listener from here attached. + socket.removeListener('error', cb) + } + + return cb_(er, parsed, raw, response) + }) var parsed = url.parse(uri) var headers = {} @@ -149,8 +158,13 @@ function makeRequest (uri, params, cb_) { var req = request(opts, decodeResponseBody(done)) req.on('error', cb) + + // This should not be necessary, as the HTTP implementation in Node + // passes errors occurring on the socket to the request itself. Being overly + // cautious comes at a low cost, though. req.on('socket', function (s) { - s.on('error', cb) + socket = s + socket.on('error', cb) }) if (params.body && (params.body instanceof Stream)) { diff --git a/test/lib/common.js b/test/lib/common.js index 78e543f..ea48d30 100644 --- a/test/lib/common.js +++ b/test/lib/common.js @@ -10,6 +10,14 @@ if (!global.setImmediate || !require('timers').setImmediate) { } } +// See https://github.com/npm/npm-registry-client/pull/142 for background. +// Note: `process.on('warning')` only works with Node >= 6. +process.on('warning', function (warning) { + if (/Possible EventEmitter memory leak detected/.test(warning.message)) { + throw new Error('There should not be any EventEmitter memory leaks') + } +}) + module.exports = { port: server.port, registry: REGISTRY,