Skip to content

fix: conns opened while closing the pool are not closed - #121

Merged
quettabit merged 1 commit into
mainfrom
qb/97
Sep 10, 2026
Merged

quettabit merged 1 commit into
mainfrom
qb/97

Conversation

@quettabit

@quettabit quettabit commented Sep 10, 2026

Copy link
Copy Markdown
Member

closes #97

@quettabit quettabit changed the title [WIP] fix: conns opened while closing the pool are not closed fix: conns opened while closing the pool are not closed Sep 10, 2026
@quettabit
quettabit marked this pull request as ready for review September 10, 2026 19:57
@quettabit
quettabit requested a review from a team as a code owner September 10, 2026 19:57
@greptile-apps

greptile-apps Bot commented Sep 10, 2026

Copy link
Copy Markdown

Greptile Summary

Fixes a connection-pool shutdown race by checking whether the pool closed before publishing a newly opened connection.

  • Closes the new connection and raises S2ClientError when shutdown wins the race.
  • Avoids temporarily adding zero-capacity connections to the pool.
  • Updates the zero-stream-capacity test to reflect the revised bookkeeping.

Confidence Score: 5/5

The PR appears safe to merge, with no outstanding correctness or repository-rule violations.

The shutdown-race fix closes a connection before raising when the pool has closed and prevents rejected zero-capacity connections from entering pool state. The prior test-coverage thread was resolved after quettabit dismissed it, explaining that additional tests are left to human discretion.

Important Files Changed

Filename Overview
src/s2_sdk/_client.py Adds an atomic pre-publication lifecycle check that closes a newly opened connection when pool shutdown wins the race.
tests/test_client.py Updates the zero-capacity assertion because rejected connections are no longer inserted into the host map.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Pool
    participant Connection
    participant Shutdown

    Caller->>Pool: checkout(base_url)
    Pool->>Connection: open and negotiate SETTINGS
    Shutdown->>Pool: close()
    Pool->>Pool: mark closed
    Connection-->>Pool: negotiation completes
    Pool->>Pool: _add_connection()
    alt Pool is closed
        Pool->>Connection: close()
        Pool-->>Caller: raise S2ClientError
    else Pool remains open
        Pool->>Pool: publish connection
        Pool-->>Caller: return checkout
    end
Loading

Reviews (2): Last reviewed commit: "initial commit" | Re-trigger Greptile

Comment thread tests/test_client.py
@quettabit
quettabit merged commit 6e3cd2f into main Sep 10, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] SDK: Connection pool can create orphaned HTTP/2 connections after close()

1 participant