(reason: StopReason)
| 70 | } |
| 71 | |
| 72 | private async gracefulStopAndExit(reason: StopReason): Promise<void> { |
| 73 | try { |
| 74 | await Promise.race([ |
| 75 | this.gracefulStop(), |
| 76 | new Promise<void>((resolve) => { |
| 77 | setTimeout(() => { |
| 78 | console.warn("[Lifecycle] Graceful stop timed out, forcing exit."); |
| 79 | resolve(); |
| 80 | }, STOP_TIMEOUT_MS); |
| 81 | }), |
| 82 | ]); |
| 83 | } catch (err) { |
| 84 | console.error("[Lifecycle] Error during graceful stop:", err); |
| 85 | } |
| 86 | |
| 87 | const exitCode = |
| 88 | reason === "restart" ? RESTART_EXIT_CODE : SHUTDOWN_EXIT_CODE; |
| 89 | this.exitFn(exitCode); |
| 90 | } |
| 91 | |
| 92 | private async gracefulStop(): Promise<void> { |
| 93 | for (const adapter of [...this.adapters].reverse()) { |
no test coverage detected