fix(PortProxy): Enhance connection cleanup handling in PortProxy
This commit is contained in:
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartproxy',
|
||||
version: '3.20.1',
|
||||
version: '3.20.2',
|
||||
description: 'A powerful proxy package that effectively handles high traffic, with features such as SSL/TLS support, port proxying, WebSocket handling, and dynamic routing with authentication options.'
|
||||
}
|
||||
|
@ -354,6 +354,7 @@ export class PortProxy {
|
||||
|
||||
// Initialize a cleanup timer for max connection lifetime.
|
||||
if (this.settings.maxConnectionLifetime) {
|
||||
// Flags to track if data was seen from each side.
|
||||
let incomingActive = false;
|
||||
let outgoingActive = false;
|
||||
const resetCleanupTimer = () => {
|
||||
@ -370,15 +371,19 @@ export class PortProxy {
|
||||
|
||||
resetCleanupTimer();
|
||||
|
||||
// Only reset the timer if outgoing socket is still active.
|
||||
socket.on('data', () => {
|
||||
incomingActive = true;
|
||||
if (incomingActive && outgoingActive) {
|
||||
// Check if outgoing has not been closed before resetting timer.
|
||||
if (!connectionRecord.outgoingClosedTime && incomingActive && outgoingActive) {
|
||||
resetCleanupTimer();
|
||||
incomingActive = false;
|
||||
outgoingActive = false;
|
||||
}
|
||||
});
|
||||
targetSocket.on('data', () => {
|
||||
// If outgoing is closed, do not set outgoingActive.
|
||||
if (connectionRecord.outgoingClosedTime) return;
|
||||
outgoingActive = true;
|
||||
if (incomingActive && outgoingActive) {
|
||||
resetCleanupTimer();
|
||||
|
Reference in New Issue
Block a user