Stop the ClickHouse service from reopening clients after shutdown

Merged
AB
12h ago
+22-6

What

ClickHouseService.onModuleDestroy closed its clients but left them in mainClient and clients. An insert landing after shutdown (a late event-log write from a test teardown, for instance) picked the closed client back up, or created a fresh one through connectToClient, and opened a new socket. Jest then never exited and the integration shard ran into its 30-minute timeout with every test passing.

  • onModuleDestroy marks the service destroyed, empties mainClient and clients, then closes what it held.
  • connectToClient returns undefined once the service is destroyed, and closes a client that finished initialising after shutdown instead of keeping it.

Callers already treat an undefined client as "ClickHouse not configured", so a late insert is dropped instead of reopening a connection.

Why now

Server integration shard 16 hung this way twice in a row on #30521 (all 320 tests passed, the job was cancelled at the timeout). Split out of that PR so the settings page stays front-end only.

Test

Typecheck, lint and the server unit suites passed on these exact commits in #30521's CI.