mirror of
https://github.com/bitinflow/server.git
synced 2026-03-13 13:35:53 +00:00
cleanup if server close throws
This commit is contained in:
18
proxy.js
18
proxy.js
@@ -40,15 +40,20 @@ var Proxy = function(opt, cb) {
|
||||
function maybe_tcp_close() {
|
||||
clearTimeout(conn_timeout);
|
||||
conn_timeout = setTimeout(function() {
|
||||
client_server.close();
|
||||
clearTimeout(conn_timeout);
|
||||
|
||||
// sometimes the server is already closed but the event has not fired?
|
||||
try {
|
||||
clearTimeout(conn_timeout);
|
||||
client_server.close();
|
||||
} catch (err) {
|
||||
cleanup();
|
||||
}
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
maybe_tcp_close();
|
||||
|
||||
// no longer accepting connections for this id
|
||||
client_server.on('close', function() {
|
||||
function cleanup() {
|
||||
debug('closed tcp socket for client(%s)', id);
|
||||
|
||||
clearTimeout(conn_timeout);
|
||||
@@ -59,7 +64,10 @@ var Proxy = function(opt, cb) {
|
||||
});
|
||||
|
||||
self.emit('end');
|
||||
});
|
||||
}
|
||||
|
||||
// no longer accepting connections for this id
|
||||
client_server.on('close', cleanup);
|
||||
|
||||
// new tcp connection from lt client
|
||||
client_server.on('connection', function(socket) {
|
||||
|
||||
Reference in New Issue
Block a user