Rebuild: the coordinator stops on SIGTERM

It waited for every chunk in flight, and a connection the server held
back (after killed coordinators left sessions open) waits up to the
10-minute reply timeout: it never seemed to stop. It now waits at most
15 s, then closes all connections, busy ones too; the greeting and login
time out after 30 s. And run() ends with terminate(), as edge:node does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daan MeijerandClaude Opus 5.5 committed 2026-10-09 03:20:11 +02:00
1 parent cae6e4f60d
commit 883d85e91d
3 files changed
+16 -3

No files matched your search

+8 -1
View File
@@ -11,6 +11,7 @@ const TICK_MS = 2000
const PLAN_EVERY_MS = 60 * 60 * 1000
const MERGE_EVERY_MS = 60 * 1000
const MERGE_BUDGET_MS = 30 * 1000
const STOP_WAIT_MS = 15 * 1000
/**
* The coordinator's background work (REBUILD.md, part 1): the prefetcher,
@@ -30,6 +31,7 @@ export default class CoordinatorRun extends BaseCommand {
const done = new Promise<void>((resolve) => (stopped = resolve))
// bin/console turns SIGTERM into app.terminate: wait for the spooling in flight first.
this.app.terminating(async () => {
this.logger.info('Stopping: waiting for the chunks in flight.')
stopping = true
prefetcher.stop()
await done
@@ -83,8 +85,13 @@ export default class CoordinatorRun extends BaseCommand {
await sleep(TICK_MS)
}
await prefetching
while (prefetcher.active > 0) await sleep(200)
// The chunks in flight, for at most STOP_WAIT_MS (a connection the server holds back can take minutes); then closed.
const waitUntil = Date.now() + STOP_WAIT_MS
while (prefetcher.active > 0 && Date.now() < waitUntil) await sleep(200)
if (prefetcher.active > 0) this.logger.info(`Closing ${prefetcher.active} connections still fetching.`)
await NntpPool.close()
this.logger.info('Coordinator stopped.')
stopped!()
await this.terminate()
}
}