Skip to content

WorkerSessionManager: overlapping ensureWorker() calls during SRV preparation can orphan a worker #1002

Open

Description

Found in the PR #997 review (finding P5, latent, low severity).

Problem

WorkerSessionManager.initializeWorker() now awaits prepareDriverConnectionString() (the SRV probe and, if needed, the DNS fallback) before it assigns _worker. ensureWorker() decides whether to spawn with !this._worker || this._workerState === 'idle'.

If a second ensureWorker() call arrives while SRV preparation is still running, it starts a second spawn:

  • it replaces _startupAbortController without aborting the first one;
  • both startups create a Worker; the second assignment overwrites _worker;
  • the first worker thread, and its client, are never terminated.

Before PR #997 there was no await between the check and the assignment, so the window did not exist.

Why it does not happen today

Current callers serialize: the query playground checks isExecuting(clusterId), and the shell calls initialize() once. PR #997 records this with a one-line comment in ensureWorker().

Proposed fix (option A from the review)

Track the in-flight startup:

  • keep the spawn promise and its clusterId;
  • a same-cluster call awaits the in-flight promise instead of spawning;
  • a different-cluster call calls terminateWorker() first (which already aborts the startup controller), then spawns.

This also stops a second caller from sending eval to a worker that is still starting.

Tests: two overlapping ensureWorker() calls for the same cluster create one worker; overlapping calls for different clusters abort the first startup and leave exactly one worker.

Review file: docs/ai-and-plans/features/srv-dns-fallback/iterations/01-srv-fallback/pr-997-review.md (P5).

Activity

  1. added a commit that references this issue on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions