Skip to content

fix: close client on authenticate() failure to prevent socket/task leak in ClientPool - #279

Merged
Gsantomaggio merged 1 commit into
masterfrom
fix/clientpool-authenticate-leak-278
Sep 22, 2026
Merged

Gsantomaggio merged 1 commit into
masterfrom
fix/clientpool-authenticate-leak-278

Conversation

@Gsantomaggio

@Gsantomaggio Gsantomaggio commented Sep 21, 2026 •

Copy link
Copy Markdown
Member

Fixes: #278
ClientPool.new() left partially-initialized clients unclosed and untracked whenever authenticate() raised after start() had already opened the connection (e.g. an OAuth2 timeout), leaking a socket and listener task on every failure. Connection.close() is also made a safe no-op when the socket never finished opening, so close() can't itself raise if start() fails before authenticate() is reached.

…ak in ClientPool

ClientPool.new() left partially-initialized clients unclosed and untracked
whenever authenticate() raised after start() had already opened the
connection (e.g. an OAuth2 timeout), leaking a socket and listener task on
every failure. Connection.close() is also made a safe no-op when the
socket never finished opening, so close() can't itself raise if start()
fails before authenticate() is reached.

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
@Gsantomaggio Gsantomaggio self-assigned this Sep 21, 2026
@Gsantomaggio Gsantomaggio added the bug-fix PR fixes a bug label Sep 21, 2026
@Gsantomaggio Gsantomaggio added this to the v1.1.1 milestone Sep 21, 2026
@Gsantomaggio Gsantomaggio changed the title fix: close client on authenticate() failure to prevent socket/task le… fix: close client on authenticate() failure to prevent socket/task leak in ClientPool Sep 21, 2026
@Gsantomaggio
Gsantomaggio requested a lite review from Copilot September 21, 2026 11:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

Only a non-blocking test-coverage nit remains.

Review effort: Lite
Findings: None

What changed in this PR

Fixes leaked sockets and listener tasks when client startup or authentication fails.

Changes:

  • Cleans up partially initialized clients on failure.
  • Makes Connection.close() safe before socket creation.
  • Adds authentication-failure regression coverage.
File Summary
tests/​test_client.py Tests cleanup after authentication failure.
rstream/​connection.py Safely handles unopened connections.
rstream/​client.py Cleans up failed client initialization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Gsantomaggio
Gsantomaggio merged commit 48164ba into master Sep 22, 2026
2 checks passed
@Gsantomaggio
Gsantomaggio deleted the fix/clientpool-authenticate-leak-278 branch September 22, 2026 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClientPool.new() leaks socket + listener task when authenticate() raises

2 participants