Skip to content

Commit

Permalink
Ensure that idle sockets are automatically closed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericbarch committed Aug 25, 2018
1 parent 9b44eba commit b4d39fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
7 changes: 7 additions & 0 deletions 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
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 0 additions & 5 deletions server.js
Expand Up @@ -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);
});

Expand Down

0 comments on commit b4d39fc

Please sign in to comment.