Remove Force Close to fix WebSockets
This commit is contained in:
@ -12,7 +12,7 @@ const CONFIG = {
|
||||
PORT: 8081,
|
||||
WORKER_MULTIPLIER: 4,
|
||||
PROXY_TIMEOUT: 360000, // 6 minutes
|
||||
TUNNEL_TIMEOUT: 20000, // Reduced to 20 seconds for faster socket cleanup
|
||||
TUNNEL_TIMEOUT: 20000, // 20 seconds for socket timeout
|
||||
DEBUG: false, // Keep enabled for diagnostics
|
||||
CONINFO: false,
|
||||
MAX_SOCKETS: 500,
|
||||
@ -21,7 +21,7 @@ const CONFIG = {
|
||||
PORT_RANGE_END: 20000,
|
||||
CONNECT_RETRY_MS: 100,
|
||||
MAX_CONNECT_RETRIES: 3,
|
||||
TUNNEL_FORCE_CLOSE_MS: 10000, // Reduced to 10 seconds for faster cleanup
|
||||
TUNNEL_FORCE_CLOSE_MS: 10000, // Not used anymore
|
||||
};
|
||||
|
||||
// Shared HTTP agent
|
||||
@ -91,23 +91,15 @@ if (cluster.isMaster) {
|
||||
activeTunnels.set(tunnelServer, { id: tunnelId, port, created: Date.now() });
|
||||
if (CONFIG.DEBUG) console.log(`Created ${tunnelId}, active tunnels: ${activeTunnels.size}`);
|
||||
|
||||
const forceCloseTimeout = setTimeout(() => {
|
||||
// console.warn(`Force closing ${tunnelId} after ${CONFIG.TUNNEL_FORCE_CLOSE_MS}ms`);
|
||||
closeTunnel(tunnelServer);
|
||||
}, CONFIG.TUNNEL_FORCE_CLOSE_MS);
|
||||
|
||||
await proxyWithRetry(req, res, port, proxy, () => {
|
||||
clearTimeout(forceCloseTimeout);
|
||||
closeTunnel(tunnelServer);
|
||||
});
|
||||
|
||||
res.on('finish', () => {
|
||||
clearTimeout(forceCloseTimeout);
|
||||
closeTunnel(tunnelServer);
|
||||
});
|
||||
res.on('error', (err) => {
|
||||
if (CONFIG.DEBUG) console.error(`Response error for ${tunnelId}:`, err.message);
|
||||
clearTimeout(forceCloseTimeout);
|
||||
closeTunnel(tunnelServer);
|
||||
});
|
||||
} catch (e) {
|
||||
@ -145,23 +137,15 @@ if (cluster.isMaster) {
|
||||
activeTunnels.set(tunnelServer, { id: tunnelId, port, created: Date.now() });
|
||||
if (CONFIG.DEBUG) console.log(`Created ${tunnelId}, active tunnels: ${activeTunnels.size}`);
|
||||
|
||||
const forceCloseTimeout = setTimeout(() => {
|
||||
console.warn(`Force closing ${tunnelId} after ${CONFIG.TUNNEL_FORCE_CLOSE_MS}ms`);
|
||||
closeTunnel(tunnelServer);
|
||||
}, CONFIG.TUNNEL_FORCE_CLOSE_MS);
|
||||
|
||||
await proxyWsWithRetry(req, socket, head, port, proxy, () => {
|
||||
clearTimeout(forceCloseTimeout);
|
||||
closeTunnel(tunnelServer);
|
||||
});
|
||||
|
||||
socket.on('close', () => {
|
||||
clearTimeout(forceCloseTimeout);
|
||||
closeTunnel(tunnelServer);
|
||||
});
|
||||
socket.on('error', (err) => {
|
||||
if (CONFIG.DEBUG) console.error(`WebSocket error for ${tunnelId}:`, err.message);
|
||||
clearTimeout(forceCloseTimeout);
|
||||
closeTunnel(tunnelServer);
|
||||
});
|
||||
} catch (e) {
|
||||
@ -194,7 +178,7 @@ if (cluster.isMaster) {
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 5000); // Reduced to 5 seconds for faster feedback
|
||||
}, 5000); // 5 seconds for feedback
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user