From 8be9d945d03169056bbf84d702292b5763b015dc Mon Sep 17 00:00:00 2001 From: John Catron Date: Thu, 14 Aug 2014 20:12:20 +0000 Subject: [PATCH] updated close function for safety --- lib/http-proxy/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/http-proxy/index.js b/lib/http-proxy/index.js index a33084f83..070c6db51 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); } };