* Called when the child bridge process exits, if Homebridge is not shutting down, it will restart the process * @param code * @param signal
(code: number | null, signal: string | null)
| 510 | * @param signal |
| 511 | */ |
| 512 | private handleProcessClose(code: number | null, signal: string | null): void { |
| 513 | const isLikelyPluginCrash = code === 1 && signal === null |
| 514 | this.log.warn(`Child bridge ended (code ${code}, signal ${signal}).${isLikelyPluginCrash |
| 515 | ? ' The child bridge ended unexpectedly, which is normally due to the plugin not catching its errors properly. Please report this to the plugin developer by clicking on the' |
| 516 | + ' \'Report An Issue\' option in the plugin menu dropdown from the Homebridge UI. If there are related logs shown above, please include them in your report.' |
| 517 | : ''}`) |
| 518 | |
| 519 | if (isLikelyPluginCrash) { |
| 520 | if (this.restartCount < this.maxRestarts) { |
| 521 | this.bridgeStatus = ChildBridgeStatus.PENDING |
| 522 | this.restartCount += 1 |
| 523 | const delay = this.restartCount * 10 // first attempt after 10 seconds, second after 20 seconds, etc. |
| 524 | this.log(`Child bridge will automatically restart in ${delay} seconds (restart attempt ${this.restartCount} of ${this.maxRestarts}).`) |
| 525 | this.scheduledRestartTimeout = setTimeout(() => { |
| 526 | this.scheduledRestartTimeout = undefined |
| 527 | if (!this.shuttingDown && !this.manuallyStopped) { |
| 528 | this.startChildProcess() |
| 529 | } |
| 530 | }, delay * 1000) |
| 531 | } else { |
| 532 | this.bridgeStatus = ChildBridgeStatus.DOWN |
| 533 | this.manuallyStopped = true |
| 534 | this.log.error(`Child bridge will no longer restart after failing ${this.maxRestarts + 1} times, you will need to manually start this child bridge from the Homebridge UI.`) |
| 535 | } |
| 536 | return |
| 537 | } |
| 538 | |
| 539 | if (!this.shuttingDown) { |
| 540 | this.bridgeStatus = ChildBridgeStatus.DOWN |
| 541 | this.restartCount = 0 |
| 542 | this.startChildProcess() |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * Helper function to send a message to the child process |
no test coverage detected