MCPcopy Create free account
hub / github.com/callstack/agent-device / shutdown

Function shutdown

src/daemon/server/daemon-runtime.ts:241–270  ·  view source on GitHub ↗
(shutdownOptions: { exitCode?: number; cause?: unknown } = {})

Source from the content-addressed store, hash-verified

239
240 let shuttingDown = false;
241 const shutdown = async (shutdownOptions: { exitCode?: number; cause?: unknown } = {}) => {
242 if (shuttingDown) return;
243 shuttingDown = true;
244 if (shutdownOptions.cause) {
245 await emitFatalDiagnostic(shutdownOptions.cause);
246 }
247 await closeDaemonServers(servers);
248 // Hand healthy simulator runners off to the next daemon before session
249 // teardown gets a chance to kill them; everything left after this
250 // (real devices, unhealthy runners) goes through the normal stop path.
251 const { detachIosSimulatorRunnerSessionsForShutdown, stopAllIosRunnerSessions } =
252 await import('../../platforms/apple/core/runner/runner-client.ts');
253 try {
254 await detachIosSimulatorRunnerSessionsForShutdown();
255 } catch {}
256 await teardownDaemonSessions();
257 await Promise.allSettled(
258 providerDeviceRuntimes.map(async (runtime) => await runtime.shutdown()),
259 );
260 await stopAllIosRunnerSessions();
261 // Best effort: stop the PNG worker so an in-flight job cannot delay exit.
262 await Promise.race([
263 terminatePngWorker().catch(() => {}),
264 sleep(DAEMON_PNG_WORKER_TERMINATE_TIMEOUT_MS),
265 ]);
266 removeInfo(infoPath);
267 releaseDaemonLock(lockPath);
268 setRunnerLeaseOwnerStateDir(undefined);
269 exit(shutdownOptions.exitCode ?? 0);
270 };
271
272 if (options.registerProcessHandlers !== false) {
273 process.on('SIGINT', () => {

Callers 1

startDaemonRuntimeFunction · 0.85

Calls 11

closeDaemonServersFunction · 0.90
terminatePngWorkerFunction · 0.90
sleepFunction · 0.90
removeInfoFunction · 0.90
releaseDaemonLockFunction · 0.90
emitFatalDiagnosticFunction · 0.85
teardownDaemonSessionsFunction · 0.85
stopAllIosRunnerSessionsFunction · 0.85
shutdownMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…