fixed problem with `destroy` in socksv5 server

This commit is contained in:
tigerbot 2017-07-10 18:24:59 -06:00
parent 2ffd846352
commit b361c0cd53
1 changed files with 6 additions and 8 deletions

View File

@ -2,16 +2,16 @@
module.exports.create = function () { module.exports.create = function () {
var PromiseA = require('bluebird'); var PromiseA = require('bluebird');
var enableDestroy = require('server-destroy');
var server; var server;
function curState() { function curState() {
if (!server) { var addr = server && server.address();
if (!addr) {
return PromiseA.resolve({running: false}); return PromiseA.resolve({running: false});
} }
return PromiseA.resolve({ return PromiseA.resolve({
running: true running: true
, port: server.address().port , port: addr.port
}); });
} }
@ -24,7 +24,9 @@ module.exports.create = function () {
accept(); accept();
}); });
enableDestroy(server); // It would be nice if we could use `server-destroy` here, but we can't because
// the socksv5 library will not give us access to any sockets it actually
// handles, so we have no way of keeping track of them or closing them.
server.on('close', function () { server.on('close', function () {
server = null; server = null;
}); });
@ -51,11 +53,7 @@ module.exports.create = function () {
return curState(); return curState();
} }
return new PromiseA(function (resolve, reject) { return new PromiseA(function (resolve, reject) {
var timeoutId = setTimeout(function () {
server.destroy();
}, 1000);
server.close(function (err) { server.close(function (err) {
clearTimeout(timeoutId);
if (err) { if (err) {
reject(err); reject(err);
} else { } else {