Skip to content

Commit

Permalink
fix: child process timeout
Browse files Browse the repository at this point in the history
Use a timeout instead of relying on the method return. method will return false when pipe is saturated, and retrying just causes more saturation.
  • Loading branch information
Balte de Wit committed Oct 8, 2018
1 parent 301c545 commit 8196d8e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/lib/atemUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ export namespace Util {
}

let handled = false
const timeout = setTimeout(() => {
reject(new Error('Failed to send IPC message'))
}, 1500)

// From https://nodejs.org/api/child_process.html#child_process_subprocess_send_message_sendhandle_options_callback:
// "subprocess.send() will return false if the channel has closed or when the backlog of
// unsent messages exceeds a threshold that makes it unwise to send more.
// Otherwise, the method returns true."
const sendResult = destProcess.send(message, (error: Error) => {
destProcess.send(message, (error: Error) => {
clearTimeout(timeout)
if (handled) {
return
}
Expand All @@ -65,15 +69,15 @@ export namespace Util {
handled = true
})

if (!sendResult && !handled) {
reject(new Error('Failed to send IPC message'))
handled = true
}
// if (!sendResult && !handled) {
// reject(new Error('Failed to send IPC message'))
// handled = true
// }
})
}, {
onFailedAttempt: error => {
if (log) {
log(`Failed to send IPC message (attempt ${error.attemptNumber}/${error.attemptNumber + error.attemptsLeft}).`)
log(`Failed to send IPC message: ${error.message} (attempt ${error.attemptNumber}/${error.attemptNumber + error.attemptsLeft}).`)
}
},
retries: 5
Expand Down

0 comments on commit 8196d8e

Please sign in to comment.