fix(tests): fix tests
This commit is contained in:
@ -274,10 +274,16 @@ export class MetricsCollector implements IMetrics {
|
||||
lastUpdate: now
|
||||
});
|
||||
|
||||
// Cleanup old request timestamps (keep last minute only)
|
||||
if (this.requestTimestamps.length > 1000) {
|
||||
// Cleanup old request timestamps
|
||||
if (this.requestTimestamps.length > 5000) {
|
||||
// First try to clean up old timestamps (older than 1 minute)
|
||||
const cutoff = now - 60000;
|
||||
this.requestTimestamps = this.requestTimestamps.filter(ts => ts > cutoff);
|
||||
|
||||
// If still too many, enforce hard cap of 5000 most recent
|
||||
if (this.requestTimestamps.length > 5000) {
|
||||
this.requestTimestamps = this.requestTimestamps.slice(-5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ export interface IConnectionRecord {
|
||||
outgoingClosedTime?: number;
|
||||
lockedDomain?: string; // Used to lock this connection to the initial SNI
|
||||
connectionClosed: boolean; // Flag to prevent multiple cleanup attempts
|
||||
cleanupTimer?: NodeJS.Timeout; // Timer for max lifetime/inactivity
|
||||
cleanupTimer?: NodeJS.Timeout | null; // Timer for max lifetime/inactivity
|
||||
alertFallbackTimeout?: NodeJS.Timeout; // Timer for fallback after alert
|
||||
lastActivity: number; // Last activity timestamp for inactivity detection
|
||||
pendingData: Buffer[]; // Buffer to hold data during connection setup
|
||||
|
@ -1302,10 +1302,13 @@ export class RouteConnectionHandler {
|
||||
enableHalfOpen: false // Default: close both when one closes (required for proxy chains)
|
||||
});
|
||||
|
||||
// Apply timeouts if keep-alive is enabled
|
||||
if (record.hasKeepAlive) {
|
||||
socket.setTimeout(this.smartProxy.settings.socketTimeout || 3600000);
|
||||
targetSocket.setTimeout(this.smartProxy.settings.socketTimeout || 3600000);
|
||||
// Apply timeouts using TimeoutManager
|
||||
const timeout = this.smartProxy.timeoutManager.getEffectiveInactivityTimeout(record);
|
||||
// Skip timeout for immortal connections (MAX_SAFE_INTEGER would cause issues)
|
||||
if (timeout !== Number.MAX_SAFE_INTEGER) {
|
||||
const safeTimeout = this.smartProxy.timeoutManager.ensureSafeTimeout(timeout);
|
||||
socket.setTimeout(safeTimeout);
|
||||
targetSocket.setTimeout(safeTimeout);
|
||||
}
|
||||
|
||||
// Log successful connection
|
||||
|
@ -94,12 +94,17 @@ export class TimeoutManager {
|
||||
public setupConnectionTimeout(
|
||||
record: IConnectionRecord,
|
||||
onTimeout: (record: IConnectionRecord, reason: string) => void
|
||||
): NodeJS.Timeout {
|
||||
): NodeJS.Timeout | null {
|
||||
// Clear any existing timer
|
||||
if (record.cleanupTimer) {
|
||||
clearTimeout(record.cleanupTimer);
|
||||
}
|
||||
|
||||
// Skip timeout for immortal keep-alive connections
|
||||
if (record.hasKeepAlive && this.smartProxy.settings.keepAliveTreatment === 'immortal') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Calculate effective timeout
|
||||
const effectiveLifetime = this.getEffectiveMaxLifetime(record);
|
||||
|
||||
|
Reference in New Issue
Block a user