Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ef060d5e79 | |||
| cd7f3f7f75 | |||
| 8df18728d4 | |||
| bedecc6b6b | |||
| b5f166bc92 | |||
| 94266222fe | |||
| 697d51a9d4 | |||
| 7e5fe2bec3 | |||
| f592bf627f | |||
| 6114a00fb8 |
42
changelog.md
42
changelog.md
@@ -1,5 +1,47 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 2026-02-26 - 25.8.4 - fix(proxy)
|
||||||
|
adjust default proxy timeouts and keep-alive behavior to shorter, more consistent values
|
||||||
|
|
||||||
|
- Increase connection timeout default from 30,000ms to 60,000ms (30s -> 60s).
|
||||||
|
- Reduce socket timeout default from 3,600,000ms to 60,000ms (1h -> 60s).
|
||||||
|
- Reduce max connection lifetime default from 86,400,000ms to 3,600,000ms (24h -> 1h).
|
||||||
|
- Change inactivity timeout default from 14,400,000ms to 75,000ms (4h -> 75s).
|
||||||
|
- Update keep-alive defaults: keepAliveTreatment 'extended' -> 'standard', keepAliveInactivityMultiplier 6 -> 4, extendedKeepAliveLifetime 604800000 -> 3,600,000ms (7d -> 1h).
|
||||||
|
- Apply these consistent default values across Rust crates (rustproxy-config, rustproxy-passthrough) and the TypeScript smart-proxy implementation.
|
||||||
|
- Update unit test expectations to match the new defaults.
|
||||||
|
|
||||||
|
## 2026-02-26 - 25.8.3 - fix(smartproxy)
|
||||||
|
no code or dependency changes detected; no version bump required
|
||||||
|
|
||||||
|
- No files changed in the provided diff (No changes).
|
||||||
|
- package.json version remains 25.8.2.
|
||||||
|
- No dependency or source updates detected; skip release.
|
||||||
|
|
||||||
|
## 2026-02-26 - 25.8.2 - fix(connection)
|
||||||
|
improve connection handling and timeouts
|
||||||
|
|
||||||
|
- Flush logs on process beforeExit and avoid calling process.exit in SIGINT/SIGTERM handlers to preserve host graceful shutdown
|
||||||
|
- Store protocol entries with a createdAt timestamp in ProtocolDetector and remove stale entries older than 30s to prevent leaked state from abandoned handshakes or port scanners
|
||||||
|
- Add backend connect timeout (30s) and idle timeouts (5 minutes) for dynamic forwards; destroy sockets on timeout and emit logs for timeout events
|
||||||
|
|
||||||
|
## 2026-02-25 - 25.8.1 - fix(allocator)
|
||||||
|
switch global allocator from tikv-jemallocator to mimalloc
|
||||||
|
|
||||||
|
- Replaced tikv-jemallocator with mimalloc in rust/Cargo.toml workspace dependencies.
|
||||||
|
- Updated rust/crates/rustproxy/Cargo.toml to use mimalloc as a workspace dependency.
|
||||||
|
- Updated rust/Cargo.lock: added mimalloc and libmimalloc-sys entries and removed tikv-jemallocator and tikv-jemalloc-sys entries.
|
||||||
|
- Changed the global allocator in crates/rustproxy/src/main.rs from tikv_jemallocator::Jemalloc to mimalloc::MiMalloc.
|
||||||
|
- Impact: runtime memory allocator is changed which may affect memory usage and performance; no public API changes but recommend testing memory/performance in deployments.
|
||||||
|
|
||||||
|
## 2026-02-24 - 25.8.0 - feat(rustproxy)
|
||||||
|
use tikv-jemallocator as the global allocator to reduce glibc fragmentation and slow RSS growth; add allocator dependency and enable it in rustproxy, update lockfile, and run tsrust before tests
|
||||||
|
|
||||||
|
- Added tikv-jemallocator dependency to rust/Cargo.toml and rust/crates/rustproxy/Cargo.toml
|
||||||
|
- Enabled tikv_jemallocator as the global allocator in rust/crates/rustproxy/src/main.rs
|
||||||
|
- Updated rust/Cargo.lock with tikv-jemallocator and tikv-jemalloc-sys entries
|
||||||
|
- Modified package.json test script to run tsrust before tstest
|
||||||
|
|
||||||
## 2026-02-24 - 25.7.10 - fix(rustproxy)
|
## 2026-02-24 - 25.7.10 - fix(rustproxy)
|
||||||
Use cooperative cancellation for background tasks, prune stale caches and metric entries, and switch tests to dynamic port allocation to avoid port conflicts
|
Use cooperative cancellation for background tasks, prune stale caches and metric entries, and switch tests to dynamic port allocation to avoid port conflicts
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartproxy",
|
"name": "@push.rocks/smartproxy",
|
||||||
"version": "25.7.10",
|
"version": "25.8.4",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.",
|
"description": "A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
"author": "Lossless GmbH",
|
"author": "Lossless GmbH",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "(tstest test/**/test*.ts --verbose --timeout 60 --logfile)",
|
"test": "(tsrust) && (tstest test/**/test*.ts --verbose --timeout 60 --logfile)",
|
||||||
"build": "(tsbuild tsfolders --allowimplicitany) && (tsrust)",
|
"build": "(tsbuild tsfolders --allowimplicitany) && (tsrust)",
|
||||||
"format": "(gitzone format)",
|
"format": "(gitzone format)",
|
||||||
"buildDocs": "tsdoc"
|
"buildDocs": "tsdoc"
|
||||||
|
|||||||
20
rust/Cargo.lock
generated
20
rust/Cargo.lock
generated
@@ -612,6 +612,16 @@ version = "0.2.180"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
checksum = "bcc35a38544a891a5f7c865aca548a982ccb3b8650a5b06d0fd33a10283c56fc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libmimalloc-sys"
|
||||||
|
version = "0.1.44"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "667f4fec20f29dfc6bc7357c582d91796c169ad7e2fce709468aefeb2c099870"
|
||||||
|
dependencies = [
|
||||||
|
"cc",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lock_api"
|
name = "lock_api"
|
||||||
version = "0.4.14"
|
version = "0.4.14"
|
||||||
@@ -642,6 +652,15 @@ version = "2.8.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "mimalloc"
|
||||||
|
version = "0.1.48"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e1ee66a4b64c74f4ef288bcbb9192ad9c3feaad75193129ac8509af543894fd8"
|
||||||
|
dependencies = [
|
||||||
|
"libmimalloc-sys",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "1.1.1"
|
version = "1.1.1"
|
||||||
@@ -924,6 +943,7 @@ dependencies = [
|
|||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper",
|
"hyper",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
|
"mimalloc",
|
||||||
"rcgen",
|
"rcgen",
|
||||||
"rustls",
|
"rustls",
|
||||||
"rustproxy-config",
|
"rustproxy-config",
|
||||||
|
|||||||
@@ -91,6 +91,9 @@ libc = "0.2"
|
|||||||
# Socket-level options (keepalive, etc.)
|
# Socket-level options (keepalive, etc.)
|
||||||
socket2 = { version = "0.5", features = ["all"] }
|
socket2 = { version = "0.5", features = ["all"] }
|
||||||
|
|
||||||
|
# mimalloc allocator (prevents glibc fragmentation / slow RSS growth)
|
||||||
|
mimalloc = "0.1"
|
||||||
|
|
||||||
# Internal crates
|
# Internal crates
|
||||||
rustproxy-config = { path = "crates/rustproxy-config" }
|
rustproxy-config = { path = "crates/rustproxy-config" }
|
||||||
rustproxy-routing = { path = "crates/rustproxy-routing" }
|
rustproxy-routing = { path = "crates/rustproxy-routing" }
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ impl RustProxyOptions {
|
|||||||
|
|
||||||
/// Get the effective connection timeout in milliseconds.
|
/// Get the effective connection timeout in milliseconds.
|
||||||
pub fn effective_connection_timeout(&self) -> u64 {
|
pub fn effective_connection_timeout(&self) -> u64 {
|
||||||
self.connection_timeout.unwrap_or(30_000)
|
self.connection_timeout.unwrap_or(60_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the effective initial data timeout in milliseconds.
|
/// Get the effective initial data timeout in milliseconds.
|
||||||
@@ -308,12 +308,12 @@ impl RustProxyOptions {
|
|||||||
|
|
||||||
/// Get the effective socket timeout in milliseconds.
|
/// Get the effective socket timeout in milliseconds.
|
||||||
pub fn effective_socket_timeout(&self) -> u64 {
|
pub fn effective_socket_timeout(&self) -> u64 {
|
||||||
self.socket_timeout.unwrap_or(3_600_000)
|
self.socket_timeout.unwrap_or(60_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the effective max connection lifetime in milliseconds.
|
/// Get the effective max connection lifetime in milliseconds.
|
||||||
pub fn effective_max_connection_lifetime(&self) -> u64 {
|
pub fn effective_max_connection_lifetime(&self) -> u64 {
|
||||||
self.max_connection_lifetime.unwrap_or(86_400_000)
|
self.max_connection_lifetime.unwrap_or(3_600_000)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all unique ports that routes listen on.
|
/// Get all unique ports that routes listen on.
|
||||||
@@ -377,10 +377,10 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_default_timeouts() {
|
fn test_default_timeouts() {
|
||||||
let options = RustProxyOptions::default();
|
let options = RustProxyOptions::default();
|
||||||
assert_eq!(options.effective_connection_timeout(), 30_000);
|
assert_eq!(options.effective_connection_timeout(), 60_000);
|
||||||
assert_eq!(options.effective_initial_data_timeout(), 60_000);
|
assert_eq!(options.effective_initial_data_timeout(), 60_000);
|
||||||
assert_eq!(options.effective_socket_timeout(), 3_600_000);
|
assert_eq!(options.effective_socket_timeout(), 60_000);
|
||||||
assert_eq!(options.effective_max_connection_lifetime(), 86_400_000);
|
assert_eq!(options.effective_max_connection_lifetime(), 3_600_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -118,10 +118,10 @@ pub struct ConnectionConfig {
|
|||||||
impl Default for ConnectionConfig {
|
impl Default for ConnectionConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
connection_timeout_ms: 30_000,
|
connection_timeout_ms: 60_000,
|
||||||
initial_data_timeout_ms: 60_000,
|
initial_data_timeout_ms: 60_000,
|
||||||
socket_timeout_ms: 3_600_000,
|
socket_timeout_ms: 60_000,
|
||||||
max_connection_lifetime_ms: 86_400_000,
|
max_connection_lifetime_ms: 3_600_000,
|
||||||
graceful_shutdown_timeout_ms: 30_000,
|
graceful_shutdown_timeout_ms: 30_000,
|
||||||
max_connections_per_ip: None,
|
max_connections_per_ip: None,
|
||||||
connection_rate_limit_per_minute: None,
|
connection_rate_limit_per_minute: None,
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ hyper = { workspace = true }
|
|||||||
hyper-util = { workspace = true }
|
hyper-util = { workspace = true }
|
||||||
http-body-util = { workspace = true }
|
http-body-util = { workspace = true }
|
||||||
bytes = { workspace = true }
|
bytes = { workspace = true }
|
||||||
|
mimalloc = { workspace = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
rcgen = { workspace = true }
|
rcgen = { workspace = true }
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
#[global_allocator]
|
||||||
|
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use tracing_subscriber::EnvFilter;
|
use tracing_subscriber::EnvFilter;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartproxy',
|
name: '@push.rocks/smartproxy',
|
||||||
version: '25.7.10',
|
version: '25.8.4',
|
||||||
description: 'A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.'
|
description: 'A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -354,17 +354,17 @@ export class LogDeduplicator {
|
|||||||
// Global instance for connection-related log deduplication
|
// Global instance for connection-related log deduplication
|
||||||
export const connectionLogDeduplicator = new LogDeduplicator(5000); // 5 second batches
|
export const connectionLogDeduplicator = new LogDeduplicator(5000); // 5 second batches
|
||||||
|
|
||||||
// Ensure logs are flushed on process exit
|
// Ensure logs are flushed on process exit.
|
||||||
|
// Only use beforeExit — do NOT call process.exit() from SIGINT/SIGTERM handlers
|
||||||
|
// as that kills the host process's graceful shutdown (e.g., dcrouter connection draining).
|
||||||
process.on('beforeExit', () => {
|
process.on('beforeExit', () => {
|
||||||
connectionLogDeduplicator.flushAll();
|
connectionLogDeduplicator.flushAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('SIGINT', () => {
|
process.on('SIGINT', () => {
|
||||||
connectionLogDeduplicator.cleanup();
|
connectionLogDeduplicator.cleanup();
|
||||||
process.exit(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('SIGTERM', () => {
|
process.on('SIGTERM', () => {
|
||||||
connectionLogDeduplicator.cleanup();
|
connectionLogDeduplicator.cleanup();
|
||||||
process.exit(0);
|
|
||||||
});
|
});
|
||||||
@@ -18,8 +18,8 @@ export class ProtocolDetector {
|
|||||||
private fragmentManager: DetectionFragmentManager;
|
private fragmentManager: DetectionFragmentManager;
|
||||||
private tlsDetector: TlsDetector;
|
private tlsDetector: TlsDetector;
|
||||||
private httpDetector: HttpDetector;
|
private httpDetector: HttpDetector;
|
||||||
private connectionProtocols: Map<string, 'tls' | 'http'> = new Map();
|
private connectionProtocols: Map<string, { protocol: 'tls' | 'http'; createdAt: number }> = new Map();
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.fragmentManager = new DetectionFragmentManager();
|
this.fragmentManager = new DetectionFragmentManager();
|
||||||
this.tlsDetector = new TlsDetector();
|
this.tlsDetector = new TlsDetector();
|
||||||
@@ -124,8 +124,9 @@ export class ProtocolDetector {
|
|||||||
const connectionId = DetectionFragmentManager.createConnectionId(context);
|
const connectionId = DetectionFragmentManager.createConnectionId(context);
|
||||||
|
|
||||||
// Check if we already know the protocol for this connection
|
// Check if we already know the protocol for this connection
|
||||||
const knownProtocol = this.connectionProtocols.get(connectionId);
|
const knownEntry = this.connectionProtocols.get(connectionId);
|
||||||
|
const knownProtocol = knownEntry?.protocol;
|
||||||
|
|
||||||
if (knownProtocol === 'http') {
|
if (knownProtocol === 'http') {
|
||||||
const result = this.httpDetector.detectWithContext(buffer, context, options);
|
const result = this.httpDetector.detectWithContext(buffer, context, options);
|
||||||
if (result) {
|
if (result) {
|
||||||
@@ -163,7 +164,7 @@ export class ProtocolDetector {
|
|||||||
if (!knownProtocol) {
|
if (!knownProtocol) {
|
||||||
// First peek to determine protocol type
|
// First peek to determine protocol type
|
||||||
if (this.tlsDetector.canHandle(buffer)) {
|
if (this.tlsDetector.canHandle(buffer)) {
|
||||||
this.connectionProtocols.set(connectionId, 'tls');
|
this.connectionProtocols.set(connectionId, { protocol: 'tls', createdAt: Date.now() });
|
||||||
// Handle TLS with fragment accumulation
|
// Handle TLS with fragment accumulation
|
||||||
const handler = this.fragmentManager.getHandler('tls');
|
const handler = this.fragmentManager.getHandler('tls');
|
||||||
const fragmentResult = handler.addFragment(connectionId, buffer);
|
const fragmentResult = handler.addFragment(connectionId, buffer);
|
||||||
@@ -189,7 +190,7 @@ export class ProtocolDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.httpDetector.canHandle(buffer)) {
|
if (this.httpDetector.canHandle(buffer)) {
|
||||||
this.connectionProtocols.set(connectionId, 'http');
|
this.connectionProtocols.set(connectionId, { protocol: 'http', createdAt: Date.now() });
|
||||||
const result = this.httpDetector.detectWithContext(buffer, context, options);
|
const result = this.httpDetector.detectWithContext(buffer, context, options);
|
||||||
if (result) {
|
if (result) {
|
||||||
if (result.isComplete) {
|
if (result.isComplete) {
|
||||||
@@ -221,6 +222,14 @@ export class ProtocolDetector {
|
|||||||
|
|
||||||
private cleanupInstance(): void {
|
private cleanupInstance(): void {
|
||||||
this.fragmentManager.cleanup();
|
this.fragmentManager.cleanup();
|
||||||
|
// Remove stale connectionProtocols entries (abandoned handshakes, port scanners)
|
||||||
|
const maxAge = 30_000; // 30 seconds
|
||||||
|
const now = Date.now();
|
||||||
|
for (const [id, entry] of this.connectionProtocols) {
|
||||||
|
if (now - entry.createdAt > maxAge) {
|
||||||
|
this.connectionProtocols.delete(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -242,8 +251,7 @@ export class ProtocolDetector {
|
|||||||
* @param _maxAge Maximum age in milliseconds (default: 30 seconds)
|
* @param _maxAge Maximum age in milliseconds (default: 30 seconds)
|
||||||
*/
|
*/
|
||||||
static cleanupConnections(_maxAge: number = 30000): void {
|
static cleanupConnections(_maxAge: number = 30000): void {
|
||||||
// Cleanup is now handled internally by the fragment manager
|
this.getInstance().cleanupInstance();
|
||||||
this.getInstance().fragmentManager.cleanup();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -112,12 +112,12 @@ export interface ISmartProxyOptions {
|
|||||||
maxVersion?: string;
|
maxVersion?: string;
|
||||||
|
|
||||||
// Timeout settings
|
// Timeout settings
|
||||||
connectionTimeout?: number; // Timeout for establishing connection to backend (ms), default: 30000 (30s)
|
connectionTimeout?: number; // Timeout for establishing connection to backend (ms), default: 60000 (60s)
|
||||||
initialDataTimeout?: number; // Timeout for initial data/SNI (ms), default: 60000 (60s)
|
initialDataTimeout?: number; // Timeout for initial data/SNI (ms), default: 60000 (60s)
|
||||||
socketTimeout?: number; // Socket inactivity timeout (ms), default: 3600000 (1h)
|
socketTimeout?: number; // Socket inactivity timeout (ms), default: 60000 (60s)
|
||||||
inactivityCheckInterval?: number; // How often to check for inactive connections (ms), default: 60000 (60s)
|
inactivityCheckInterval?: number; // How often to check for inactive connections (ms), default: 60000 (60s)
|
||||||
maxConnectionLifetime?: number; // Default max connection lifetime (ms), default: 86400000 (24h)
|
maxConnectionLifetime?: number; // Max connection lifetime (ms), default: 3600000 (1h)
|
||||||
inactivityTimeout?: number; // Inactivity timeout (ms), default: 14400000 (4h)
|
inactivityTimeout?: number; // Inactivity timeout (ms), default: 75000 (75s)
|
||||||
|
|
||||||
gracefulShutdownTimeout?: number; // (ms) maximum time to wait for connections to close during shutdown
|
gracefulShutdownTimeout?: number; // (ms) maximum time to wait for connections to close during shutdown
|
||||||
|
|
||||||
|
|||||||
@@ -47,16 +47,16 @@ export class SmartProxy extends plugins.EventEmitter {
|
|||||||
// Apply defaults
|
// Apply defaults
|
||||||
this.settings = {
|
this.settings = {
|
||||||
...settingsArg,
|
...settingsArg,
|
||||||
initialDataTimeout: settingsArg.initialDataTimeout || 120000,
|
initialDataTimeout: settingsArg.initialDataTimeout || 60_000,
|
||||||
socketTimeout: settingsArg.socketTimeout || 3600000,
|
socketTimeout: settingsArg.socketTimeout || 60_000,
|
||||||
maxConnectionLifetime: settingsArg.maxConnectionLifetime || 86400000,
|
maxConnectionLifetime: settingsArg.maxConnectionLifetime || 3_600_000,
|
||||||
inactivityTimeout: settingsArg.inactivityTimeout || 14400000,
|
inactivityTimeout: settingsArg.inactivityTimeout || 75_000,
|
||||||
gracefulShutdownTimeout: settingsArg.gracefulShutdownTimeout || 30000,
|
gracefulShutdownTimeout: settingsArg.gracefulShutdownTimeout || 30_000,
|
||||||
maxConnectionsPerIP: settingsArg.maxConnectionsPerIP || 100,
|
maxConnectionsPerIP: settingsArg.maxConnectionsPerIP || 100,
|
||||||
connectionRateLimitPerMinute: settingsArg.connectionRateLimitPerMinute || 300,
|
connectionRateLimitPerMinute: settingsArg.connectionRateLimitPerMinute || 300,
|
||||||
keepAliveTreatment: settingsArg.keepAliveTreatment || 'extended',
|
keepAliveTreatment: settingsArg.keepAliveTreatment || 'standard',
|
||||||
keepAliveInactivityMultiplier: settingsArg.keepAliveInactivityMultiplier || 6,
|
keepAliveInactivityMultiplier: settingsArg.keepAliveInactivityMultiplier || 4,
|
||||||
extendedKeepAliveLifetime: settingsArg.extendedKeepAliveLifetime || 7 * 24 * 60 * 60 * 1000,
|
extendedKeepAliveLifetime: settingsArg.extendedKeepAliveLifetime || 3_600_000,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize ACME options
|
// Normalize ACME options
|
||||||
|
|||||||
@@ -254,11 +254,30 @@ export class SocketHandlerServer {
|
|||||||
|
|
||||||
// Connect to the resolved target
|
// Connect to the resolved target
|
||||||
const backend = plugins.net.connect(port, host, () => {
|
const backend = plugins.net.connect(port, host, () => {
|
||||||
|
// Connection established — set idle timeout on both sides (5 min)
|
||||||
|
socket.setTimeout(300_000);
|
||||||
|
backend.setTimeout(300_000);
|
||||||
|
|
||||||
// Pipe bidirectionally
|
// Pipe bidirectionally
|
||||||
socket.pipe(backend);
|
socket.pipe(backend);
|
||||||
backend.pipe(socket);
|
backend.pipe(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Connect timeout: if backend doesn't connect within 30s, destroy both
|
||||||
|
backend.setTimeout(30_000);
|
||||||
|
|
||||||
|
backend.on('timeout', () => {
|
||||||
|
logger.log('warn', `Dynamic forward timeout to ${host}:${port}`, { component: 'socket-handler-server' });
|
||||||
|
backend.destroy();
|
||||||
|
socket.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('timeout', () => {
|
||||||
|
logger.log('debug', `Dynamic forward client idle timeout`, { component: 'socket-handler-server' });
|
||||||
|
socket.destroy();
|
||||||
|
backend.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
backend.on('error', (err) => {
|
backend.on('error', (err) => {
|
||||||
logger.log('error', `Dynamic forward backend error: ${err.message}`, { component: 'socket-handler-server' });
|
logger.log('error', `Dynamic forward backend error: ${err.message}`, { component: 'socket-handler-server' });
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user