diff --git a/client.js b/client.js index cbb3019..8f4bd15 100644 --- a/client.js +++ b/client.js @@ -1,5 +1,7 @@ 'use strict'; +const IDLE_SOCKET_TIMEOUT_MILLISECONDS = 1000 * 30; + module.exports = (options) => { return new Promise((resolve, reject) => { // require the things we need @@ -50,6 +52,11 @@ module.exports = (options) => { ss(socket).emit(clientId, s); }); + client.setTimeout(IDLE_SOCKET_TIMEOUT_MILLISECONDS); + client.on('timeout', () => { + client.end(); + }); + client.on('error', () => { // handle connection refusal (create a stream and immediately close it) let s = ss.createStream(); diff --git a/server.js b/server.js index c43bc7d..b5ea854 100644 --- a/server.js +++ b/server.js @@ -112,11 +112,6 @@ module.exports = (options) => { // Pipe all data from tunnel stream to requesting connection tunnelClientStream.pipe(req.connection); - // ensure that we kill the remote socket if the http connection drops - req.connection.on('end', () => { - tunnelClientStream.destroy(); - }); - resolve(tunnelClientStream); });