changed expected behavior when closing connections

This commit is contained in:
tigerbot 2017-04-07 18:01:47 -06:00
parent b45c6ad179
commit c0941e9afe
1 changed files with 27 additions and 10 deletions

View File

@ -27,33 +27,49 @@ function run(copts) {
} }
, closeSingle: function (cid) { , closeSingle: function (cid) {
console.log('[closeSingle]', cid);
if (!localclients[cid]) { if (!localclients[cid]) {
return; return;
} }
console.log('[closeSingle]', cid);
try { try {
localclients[cid].end(); localclients[cid].end();
} catch(e) { setTimeout(function () {
// ignore if (localclients[cid]) {
} console.warn('[closeSingle]', cid, 'connection still present');
delete localclients[cid]; delete localclients[cid];
} }
}, 500);
} catch (err) {
console.warn('[closeSingle] failed to close connection', cid, err);
delete localclients[cid];
}
}
, closeAll: function () { , closeAll: function () {
console.log('[close clients]'); console.log('[closeAll]');
Object.keys(localclients).forEach(function (cid) { Object.keys(localclients).forEach(function (cid) {
try { try {
localclients[cid].end(); localclients[cid].end();
} catch(e) { } catch (err) {
// ignore console.warn('[closeAll] failed to close connection', cid, err);
} }
delete localclients[cid];
}); });
setTimeout(function () {
Object.keys(localclients).forEach(function (cid) {
if (localclients[cid]) {
console.warn('[closeAll]', cid, 'connection still present');
delete localclients[cid];
} }
});
}, 500);
}
, count: function () { , count: function () {
return Object.keys(localclients).length; return Object.keys(localclients).length;
} }
}; };
var packerHandlers = { var packerHandlers = {
onmessage: function (opts) { onmessage: function (opts) {
var net = copts.net || require('net'); var net = copts.net || require('net');
@ -155,6 +171,7 @@ function run(copts) {
} }
} }
}; };
var wsHandlers = { var wsHandlers = {
onOpen: function () { onOpen: function () {
console.info("[open] connected to '" + copts.stunneld + "'"); console.info("[open] connected to '" + copts.stunneld + "'");
@ -185,13 +202,13 @@ function run(copts) {
, onExit: function () { , onExit: function () {
console.log('[wait] closing wstunneler...'); console.log('[wait] closing wstunneler...');
wsHandlers.retry = false; wsHandlers.retry = false;
clientHandlers.closeAll();
try { try {
wstunneler.close(); wstunneler.close();
} catch(e) { } catch(e) {
console.error("[error] wstunneler.close()"); console.error("[error] wstunneler.close()");
console.error(e); console.error(e);
// ignore process.exit(1);
} }
} }
}; };