Skip to content

fix(db): a failed reconnect leaks a pool lease, and slots are never released #1306

Closed

Description

@ZhuchkaTriplesix

Problem

In the three pools, acquire increments the entry's refs and then awaits the reconnect of a dropped connection:

entry.refs++;
if (!entry.connection.isConnected) await _reconnect(entry, mode);
return PgLease._(this, entry, entry.connection);
  • lib/core/database/postgres_connection_pool.dart:101 and :134
  • lib/core/database/mysql_connection_pool.dart:89 and :122
  • lib/core/database/sqlite_connection_pool.dart:93 and :127

When the reconnect throws (server restarted, network down), no lease is returned, so nobody releases it and refs stays raised. The entry is never idle-disposed (refs == 0 is required) and never evicted by _evictIfNeededBeforeNewSlot. Repeated failures across databases / modes fill the 32 slots with unevictable entries, and every later acquire fails with StateError: ... pool exhausted.

Scope

  • Decrement refs (and re-arm the idle timer) when the reconnect fails, in all three pools; or take the lease only after the connection is usable.
  • Test with a fake connection whose connect fails: after N failed acquires the pool can still evict and create entries.

Acceptance

  • A failed reconnect leaves refs as before the call.
  • After a failed reconnect the entry is idle-disposed after the delay.
  • maxEntries failed acquires do not exhaust the pool.

Activity

  1. added
    bugSomething isn't working
    stabilityTheme parser epic label: stability
    coreCore library logic and services
    connectionsDatabase connections, URI parsing, pools
    P1High priority / Core capability
    on Oct 10, 2026
  2. added a commit that references this issue on Oct 10, 2026
  3. ZhuchkaTriplesix commented on Oct 10, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Сделано в #1317, смержено в dev.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

P1High priority / Core capabilitybugSomething isn't workingconnectionsDatabase connections, URI parsing, poolscoreCore library logic and servicesstabilityTheme parser epic label: stability

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions