Skip to content

Commit 1ad5938

Browse files
authored
Clean up closed connections. Closes #282
1 parent 5394fa4 commit 1ad5938

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/agent.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,15 @@ Agent.prototype._open = function() {
258258
agent._handleMessage(request.data, callback);
259259
});
260260
});
261-
262-
this.stream.on('end', function() {
261+
262+
function cleanup() {
263263
agent.backend.agentsCount--;
264264
if (!agent.stream.isServer) agent.backend.remoteAgentsCount--;
265265
agent._cleanup();
266-
});
266+
}
267+
268+
this.stream.on('end', cleanup);
269+
this.stream.on('close', cleanup);
267270
};
268271

269272
// Check a request to see if its valid. Returns an error if there's a problem.

0 commit comments

Comments
 (0)