Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions src/lib/analytics-telemetry/telemetry-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,27 @@ const MAX_WORKER_LIFETIME_MS = 10000

/**
* Close stderr before exiting to avoid keeping parent process alive
* This is important when stderr is inherited in DEBUG mode
* This is only necessary when stderr is inherited in DEBUG mode
*/
function exitWorker(code: number): void {
// Use setImmediate to allow any pending stderr writes to flush
// before destroying the stream
setImmediate(() => {
// Close stderr if it was inherited (DEBUG mode)
if (process.env.DEBUG) {
try {
// Close stderr to release the file descriptor reference to parent
process.stderr.destroy()
} catch {
// Ignore errors during cleanup
// End stderr gracefully, flushing all pending writes
// This properly releases the file descriptor reference to parent
process.stderr.end(() => {
process.exit(code)
})
} finally {
// Fallback: ensure we exit even if end() fails or callback never fires
// Use setImmediate to give the end() callback a chance to run first
setImmediate(() => {
process.exit(code)
})
}

} else {
process.exit(code)
})
}
}

setTimeout(() => {
Expand Down