Skip to content

fix: concurrent conn checkouts can continue after pool close - #131

Merged
quettabit merged 1 commit into
mainfrom
qb/119
Sep 13, 2026
Merged

quettabit merged 1 commit into
mainfrom
qb/119

Conversation

@quettabit

Copy link
Copy Markdown
Member

closes #119

@quettabit
quettabit requested a review from a team as a code owner September 13, 2026 05:35
@greptile-apps

greptile-apps Bot commented Sep 13, 2026

Copy link
Copy Markdown

Greptile Summary

This PR prevents connection establishment from outliving connection-pool shutdown.

  • Tracks tasks that are creating and checking out new connections.
  • Re-checks pool closure before creating or registering a connection.
  • Cancels and awaits active connection-establishment tasks during close.
  • Closes partially initialized connections that never become pool-owned.

Confidence Score: 5/5

The PR appears safe to merge; concurrent connection establishment is cancelled and cleaned up before pool shutdown completes.

No actionable failure remains: checkout tasks are registered without an intervening suspension, closure is re-checked before pool ownership is committed, and both partial and pool-owned connections have deterministic cleanup paths.

Important Files Changed

Filename Overview
src/s2_sdk/_client.py Adds lifecycle tracking, cancellation, and partial-connection cleanup so concurrent checkouts cannot continue beyond pool shutdown.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Pool as ConnectionPool
    participant Task as Checkout task
    participant Conn as Connection

    Caller->>Pool: checkout(base_url)
    Pool->>Pool: acquire host lock and check _closed
    Pool->>Task: create and track task
    Task->>Conn: connect()
    Caller->>Pool: close()
    Pool->>Pool: "set _closed = true"
    Pool->>Task: cancel()
    Task->>Conn: close if not pool-owned
    Pool->>Pool: await checkout tasks
    Pool->>Conn: close pool-owned connections
    Pool-->>Caller: close completes
Loading

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

@quettabit
quettabit merged commit 25cf0a1 into main Sep 13, 2026
6 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] Connection pool close can leak an open socket or crash when a connection is being checked out concurrently

1 participant