Skip to content

Commit 5c564b9

Browse files
committed
fix: better exit time with node orphan process detection
1 parent a1e660c commit 5c564b9

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

src-node/node-connector.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,26 @@ const LARGE_DATA_THRESHOLD = 2*1024*1024; // 2MB
105105
let controlSocketMain = null,
106106
largeDataSocketMain = null;
107107

108-
const SOCKET_HEALTH_CHECK_INTERVAL_MS = 10 * 1000; // Interval in milliseconds
108+
const SOCKET_HEALTH_CHECK_INTERVAL_MS = 3000; // 3 seconds
109109
let healthCheckFailuresCount = 0; // Count of consecutive health check failures
110110
const RETRY_HEALTH_CHECK_MAX_COUNT = 2;
111-
setInterval(() => {
112-
if (healthCheckFailuresCount === RETRY_HEALTH_CHECK_MAX_COUNT) {
113-
console.error(`No socket connection for ${healthCheckFailuresCount * SOCKET_HEALTH_CHECK_INTERVAL_MS / 1000} seconds. Exiting due to orphan node process detection.`);
114-
process.exit(1);
115-
}
116111

117-
if (controlSocketMain || largeDataSocketMain) {
118-
// Reset failure count if any socket is connected
119-
healthCheckFailuresCount = 0;
120-
return;
121-
}
122-
console.warn(`No active sockets detected, node will be terminated in ${(RETRY_HEALTH_CHECK_MAX_COUNT-healthCheckFailuresCount)*SOCKET_HEALTH_CHECK_INTERVAL_MS/1000} seconds`);
123-
healthCheckFailuresCount++;
124-
}, SOCKET_HEALTH_CHECK_INTERVAL_MS);
112+
function startOrphanExitDetection() {
113+
setInterval(() => {
114+
if (healthCheckFailuresCount === RETRY_HEALTH_CHECK_MAX_COUNT) {
115+
console.error(`No socket connection for ${healthCheckFailuresCount * SOCKET_HEALTH_CHECK_INTERVAL_MS / 1000} seconds. Exiting due to orphan node process detection.`);
116+
process.exit(1);
117+
}
118+
119+
if (controlSocketMain || largeDataSocketMain) {
120+
// Reset failure count if any socket is connected
121+
healthCheckFailuresCount = 0;
122+
return;
123+
}
124+
console.warn(`No active sockets detected, node will be terminated in ${(RETRY_HEALTH_CHECK_MAX_COUNT-healthCheckFailuresCount)*SOCKET_HEALTH_CHECK_INTERVAL_MS/1000} seconds`);
125+
healthCheckFailuresCount++;
126+
}, SOCKET_HEALTH_CHECK_INTERVAL_MS);
127+
}
125128

126129
const MAX_PENDING_SEND_BUFFER = 10000;
127130
let pendingSendBuffer = [];
@@ -363,6 +366,7 @@ function processWSCommand(ws, metadata, dataBuffer) {
363366
ws.isLargeData = false;
364367
controlSocketMain = ws;
365368
_drainPendingSendBuffer();
369+
startOrphanExitDetection();
366370
return;
367371
case WS_COMMAND.EXEC:
368372
_execNodeConnectorFn(ws, metadata, dataBuffer);

0 commit comments

Comments
 (0)