Skip to content

[P1][bug] connect→disconnect race leaks a connection in activeConnections map (test documents as expected) #280

Closed

Description

@EVWorth

Context

connectionStore.ts's connect() and disconnect() actions both call api.* independently with no cancellation hook.

Problem

Click Connect on a slow profile, then immediately Cancel/Disconnect — the in-flight connect() resolves later and pushes the connection into activeConnections while the earlier disconnect() had nothing to remove. End state: live MySQL pool with no client-side reference, no way to close from UI without app restart. connectionStore.test.ts:393-400 explicitly documents and ships the leaky behavior as the contract.

Files

  • src/stores/connectionStore.ts:58-72, 74-90
  • src/stores/tests/connectionStore.test.ts:374-411

Repro

Open Connect on a profile that takes >500ms (latency simulation). Within 200ms click Cancel. After both settle, activeConnections has an entry for a connection the UI no longer references.

Expected

Race resolves cleanly: either the connect is cancelled before applying, or the connection is auto-disconnected after resolution when its cancel flag is set.

Proposed fix

Scope S. Track Map<profileId, AbortController> (or Set<pendingProfileIds>) in store; on disconnect(profileId) during in-flight connect, set a skip flag; on connect resolution, check flag and immediately api.disconnect. Flip the race test to assert no leak.

Acceptance

Existing race test flips from leaky to clean. Manual repro shows no activeConnections entry after connect+cancel.

Needs human verify

Yes.

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/connection
    on Jul 24, 2026
  2. EVWorth commented on Sep 7, 2026

    @EVWorth
    OwnerAuthor

    Fixed by #527. Disconnect issued before connect resolved found nothing to remove, and the resolving connect then added the entry — leaving a live pool on the server that nothing on this side could close until restart.

    Disconnect now records the intent when the id is not yet known, and a connect landing on a cancelled id closes the pool on the server rather than just dropping the reference: the pool is real, so discarding the handle is not enough. Disconnect also stopped calling the backend for an id this side does not have, which used to raise a spurious "not found" for an ordinary cancel.

    The existing test asserted the leak as the contract and was rewritten:

    // Documenting current behavior: connect wins because disconnect
    // ran before the connection was added to activeConnections.

    Not auto-closed because the PR body wrote Refs #280.

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

    area/connectionauditkind/bugseverity/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions