MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / cleanup

Function cleanup

packages/acp-adapter/src/server.ts:1013–1031  ·  view source on GitHub ↗
(signal?: NodeJS.Signals)

Source from the content-addressed store, hash-verified

1011
1012 let cleanedUp = false;
1013 const cleanup = async (signal?: NodeJS.Signals): Promise<void> => {
1014 // Idempotent: signal-then-natural-close (or vice-versa) must not
1015 // call `harness.close()` twice. `cleanedUp` is checked-and-set
1016 // synchronously so concurrent invocations cannot race.
1017 if (cleanedUp) return;
1018 cleanedUp = true;
1019 if (signal) {
1020 log.info('acp: received signal, draining harness', { signal });
1021 }
1022 try {
1023 await harness.close();
1024 } catch (err) {
1025 // The process is exiting either way; log so the diagnostic is
1026 // preserved rather than disappearing into a thrown promise.
1027 log.error('acp: harness close failed during shutdown', {
1028 error: err instanceof Error ? err.message : String(err),
1029 });
1030 }
1031 };
1032
1033 const onSigint = (): void => {
1034 void cleanup('SIGINT');

Callers 3

onSigintFunction · 0.70
onSigtermFunction · 0.70
runAcpServerFunction · 0.70

Calls 3

infoMethod · 0.65
closeMethod · 0.65
errorMethod · 0.65

Tested by

no test coverage detected