MCPcopy
hub / github.com/homebridge/homebridge / teardown

Method teardown

src/childBridgeService.ts:690–710  ·  view source on GitHub ↗

* Send sigterm to the child bridge, escalating to sigkill if the child * does not exit within 10 seconds.

()

Source from the content-addressed store, hash-verified

688 * does not exit within 10 seconds.
689 */
690 private teardown(): void {
691 // Remove the api shutdown listener so this service can be GC'd.
692 this.api.removeListener('shutdown', this._onApiShutdown)
693 this.api.setMaxListeners(Math.max(0, this.api.getMaxListeners() - 1))
694
695 if (this.child && this.child.connected) {
696 this.bridgeStatus = ChildBridgeStatus.DOWN
697 const child = this.child
698 child.kill('SIGTERM')
699 // If the child has not exited within 10s, escalate to SIGKILL.
700 // The 'close' handler will clear this in the normal-exit path because
701 // child.connected becomes false before close fires.
702 const sigkillTimer = setTimeout(() => {
703 if (child.connected) {
704 this.log.warn('Child bridge did not exit within 10s of SIGTERM; escalating to SIGKILL.')
705 child.kill('SIGKILL')
706 }
707 }, 10000)
708 sigkillTimer.unref()
709 }
710 }
711
712 /**
713 * Trigger sending child bridge metadata to the process parent via IPC

Callers 3

ChildBridgeServiceClass · 0.95
restartChildBridgeMethod · 0.95
stopChildBridgeMethod · 0.95

Calls 2

killMethod · 0.80
warnMethod · 0.80

Tested by

no test coverage detected