use pump to pipe sockets

Ensures that destination socket close or destroy also does the same for
the source socket.
This commit is contained in:
Roman Shtylman
2018-05-16 10:21:56 -04:00
parent 743895720c
commit 317db73bdc
7 changed files with 97 additions and 50 deletions

View File

@@ -20,6 +20,8 @@ class ClientManager {
};
this.debug = Debug('lt:ClientManager');
this.graceTimeout = null;
}
// create a new tunnel with `id`
@@ -36,11 +38,13 @@ class ClientManager {
const maxSockets = this.opt.max_tcp_sockets;
const agent = new TunnelAgent({
clientId: id,
maxSockets: 10,
});
agent.on('online', () => {
this.debug('client online %s', id);
clearTimeout(this.graceTimeout);
});
agent.on('offline', () => {
@@ -48,7 +52,11 @@ class ClientManager {
// this period is short as the client is expected to maintain connections actively
// if they client does not reconnect on a dropped connection they need to re-establish
this.debug('client offline %s', id);
this.removeClient(id);
// client is given a grace period in which they can re-connect before they are _removed_
this.graceTimeout = setTimeout(() => {
this.removeClient(id);
}, 1000);
});
// TODO(roman): an agent error removes the client, the user needs to re-connect?
@@ -81,6 +89,7 @@ class ClientManager {
}
removeClient(id) {
this.debug('removing client: %s', id);
const client = this.clients[id];
if (!client) {
return;