Enhance socket cleanup and management for improved connection handling

- Refactor cleanupSocket function to support options for immediate destruction, allowing drain, and grace periods.
- Introduce createIndependentSocketHandlers for better management of half-open connections between client and server sockets.
- Update various handlers (HTTP, HTTPS passthrough, HTTPS terminate) to utilize new cleanup and socket management functions.
- Implement custom timeout handling in socket setup to prevent immediate closure during keep-alive connections.
- Add tests for long-lived connections and half-open connection scenarios to ensure stability and reliability.
- Adjust connection manager to handle socket cleanup based on activity status, improving resource management.
This commit is contained in:
2025-06-01 12:27:15 +00:00
parent 265b80ee04
commit ad80798210
13 changed files with 728 additions and 1223 deletions

View File

@ -112,7 +112,7 @@ export class HttpsTerminateToHttpHandler extends ForwardingHandler {
});
// Set up error handling with our cleanup utility
setupSocketHandlers(tlsSocket, handleClose, 'tls');
setupSocketHandlers(tlsSocket, handleClose, undefined, 'tls');
// Set timeout
const timeout = this.getTimeout();
@ -167,7 +167,7 @@ export class HttpsTerminateToHttpHandler extends ForwardingHandler {
});
// Set up handlers for backend socket
setupSocketHandlers(backendSocket, newHandleClose, 'backend');
setupSocketHandlers(backendSocket, newHandleClose, undefined, 'backend');
backendSocket.on('error', (error) => {
this.emit(ForwardingHandlerEvents.ERROR, {