Update proxy to force close http but not websocket.
This commit is contained in:
@ -12,7 +12,7 @@ const CONFIG = {
|
|||||||
PORT: 8081,
|
PORT: 8081,
|
||||||
WORKER_MULTIPLIER: 4,
|
WORKER_MULTIPLIER: 4,
|
||||||
PROXY_TIMEOUT: 360000, // 6 minutes
|
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
|
DEBUG: false, // Keep enabled for diagnostics
|
||||||
CONINFO: false,
|
CONINFO: false,
|
||||||
MAX_SOCKETS: 500,
|
MAX_SOCKETS: 500,
|
||||||
@ -21,7 +21,7 @@ const CONFIG = {
|
|||||||
PORT_RANGE_END: 20000,
|
PORT_RANGE_END: 20000,
|
||||||
CONNECT_RETRY_MS: 100,
|
CONNECT_RETRY_MS: 100,
|
||||||
MAX_CONNECT_RETRIES: 3,
|
MAX_CONNECT_RETRIES: 3,
|
||||||
TUNNEL_FORCE_CLOSE_MS: 10000, // Not used anymore
|
TUNNEL_FORCE_CLOSE_MS: 10000, // Used for HTTP requests
|
||||||
};
|
};
|
||||||
|
|
||||||
// Shared HTTP agent
|
// Shared HTTP agent
|
||||||
@ -91,15 +91,23 @@ if (cluster.isMaster) {
|
|||||||
activeTunnels.set(tunnelServer, { id: tunnelId, port, created: Date.now() });
|
activeTunnels.set(tunnelServer, { id: tunnelId, port, created: Date.now() });
|
||||||
if (CONFIG.DEBUG) console.log(`Created ${tunnelId}, active tunnels: ${activeTunnels.size}`);
|
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, () => {
|
await proxyWithRetry(req, res, port, proxy, () => {
|
||||||
|
clearTimeout(forceCloseTimeout);
|
||||||
closeTunnel(tunnelServer);
|
closeTunnel(tunnelServer);
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('finish', () => {
|
res.on('finish', () => {
|
||||||
|
clearTimeout(forceCloseTimeout);
|
||||||
closeTunnel(tunnelServer);
|
closeTunnel(tunnelServer);
|
||||||
});
|
});
|
||||||
res.on('error', (err) => {
|
res.on('error', (err) => {
|
||||||
if (CONFIG.DEBUG) console.error(`Response error for ${tunnelId}:`, err.message);
|
if (CONFIG.DEBUG) console.error(`Response error for ${tunnelId}:`, err.message);
|
||||||
|
clearTimeout(forceCloseTimeout);
|
||||||
closeTunnel(tunnelServer);
|
closeTunnel(tunnelServer);
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} 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