diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index a33084f..070c6db 100644 --- a/lib/http-proxy/index.js +++ b/lib/http-proxy/index.js @@ -134,8 +134,16 @@ ProxyServer.prototype.listen = function(port, hostname) { ProxyServer.prototype.close = function(callback) { if (this._server) { - this._server.close(callback); - this._server = null; + // Wrap callback to nullify server after all open connections are closed. + var callback_wrapper = function() { + this._server = null; + + if (callback) { + callback(arguments); + } + }; + + this._server.close(callback_wrapper); } };