Skip to content

Commit

Permalink
fix: node crashes after computer sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
abose committed Sep 2, 2024
1 parent 3dd832d commit ba5800d
Showing 1 changed file with 0 additions and 22 deletions.
22 changes: 0 additions & 22 deletions src-node/node-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,6 @@ const LARGE_DATA_THRESHOLD = 2*1024*1024; // 2MB
let controlSocketMain = null,
largeDataSocketMain = null;

const SOCKET_HEALTH_CHECK_INTERVAL_MS = 3000; // 3 seconds
let healthCheckFailuresCount = 0; // Count of consecutive health check failures
const RETRY_HEALTH_CHECK_MAX_COUNT = 2;

function startOrphanExitDetection() {
setInterval(() => {
if (healthCheckFailuresCount === RETRY_HEALTH_CHECK_MAX_COUNT) {
console.error(`No socket connection for ${healthCheckFailuresCount * SOCKET_HEALTH_CHECK_INTERVAL_MS / 1000} seconds. Exiting due to orphan node process detection.`);
process.exit(1);
}

if (controlSocketMain || largeDataSocketMain) {
// Reset failure count if any socket is connected
healthCheckFailuresCount = 0;
return;
}
console.warn(`No active sockets detected, node will be terminated in ${(RETRY_HEALTH_CHECK_MAX_COUNT-healthCheckFailuresCount)*SOCKET_HEALTH_CHECK_INTERVAL_MS/1000} seconds`);
healthCheckFailuresCount++;
}, SOCKET_HEALTH_CHECK_INTERVAL_MS);
}

const MAX_PENDING_SEND_BUFFER = 10000;
let pendingSendBuffer = [];

Expand Down Expand Up @@ -366,7 +345,6 @@ function processWSCommand(ws, metadata, dataBuffer) {
ws.isLargeData = false;
controlSocketMain = ws;
_drainPendingSendBuffer();
startOrphanExitDetection();
return;
case WS_COMMAND.EXEC:
_execNodeConnectorFn(ws, metadata, dataBuffer);
Expand Down

0 comments on commit ba5800d

Please sign in to comment.