Update proxy to force close http but not websocket.
This commit is contained in:
@ -12,7 +12,7 @@ const CONFIG = {
|
||||
PORT: 8081,
|
||||
WORKER_MULTIPLIER: 4,
|
||||
PROXY_TIMEOUT: 360000, // 6 minutes
|
||||
TUNNEL_TIMEOUT: 20000, // 20 seconds for socket timeout
|
||||
TUNNEL_TIMEOUT: 3600000, // Increased to 1 hour for long-lived WebSocket connections
|
||||
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, // Not used anymore
|
||||
TUNNEL_FORCE_CLOSE_MS: 10000, // Used for HTTP requests
|
||||
};
|
||||
|
||||
// Shared HTTP agent
|
||||
@ -91,15 +91,23 @@ 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) {
|
||||
@ -178,7 +186,7 @@ if (cluster.isMaster) {
|
||||
});
|
||||
}
|
||||
}
|
||||
}, 5000); // 5 seconds for feedback
|
||||
}, 5000); // Reduced to 5 seconds for faster feedback
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user