From c0941e9afedd2494ffca79a250750627e871eb40 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Fri, 7 Apr 2017 18:01:47 -0600 Subject: [PATCH] changed expected behavior when closing connections --- wsclient.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/wsclient.js b/wsclient.js index 0f9e2c6..309f39a 100644 --- a/wsclient.js +++ b/wsclient.js @@ -27,33 +27,49 @@ function run(copts) { } , closeSingle: function (cid) { - console.log('[closeSingle]', cid); if (!localclients[cid]) { return; } + console.log('[closeSingle]', cid); try { localclients[cid].end(); - } catch(e) { - // ignore + setTimeout(function () { + if (localclients[cid]) { + console.warn('[closeSingle]', cid, 'connection still present'); + delete localclients[cid]; + } + }, 500); + } catch (err) { + console.warn('[closeSingle] failed to close connection', cid, err); + delete localclients[cid]; } - delete localclients[cid]; } , closeAll: function () { - console.log('[close clients]'); + console.log('[closeAll]'); Object.keys(localclients).forEach(function (cid) { try { localclients[cid].end(); - } catch(e) { - // ignore + } catch (err) { + 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 () { return Object.keys(localclients).length; } }; + var packerHandlers = { onmessage: function (opts) { var net = copts.net || require('net'); @@ -155,6 +171,7 @@ function run(copts) { } } }; + var wsHandlers = { onOpen: function () { console.info("[open] connected to '" + copts.stunneld + "'"); @@ -185,13 +202,13 @@ function run(copts) { , onExit: function () { console.log('[wait] closing wstunneler...'); wsHandlers.retry = false; - clientHandlers.closeAll(); + try { wstunneler.close(); } catch(e) { console.error("[error] wstunneler.close()"); console.error(e); - // ignore + process.exit(1); } } };