Skip to content

fix leak in wrappedOnClose#3785

Merged
ndyakov merged 2 commits intomasterfrom
ndyakov/fix-onClose
Apr 22, 2026
Merged

fix leak in wrappedOnClose#3785
ndyakov merged 2 commits intomasterfrom
ndyakov/fix-onClose

Conversation

@ndyakov
Copy link
Copy Markdown
Member

@ndyakov ndyakov commented Apr 22, 2026

Fixes #3772

wrappedOnClose is not needed for the Conn object. Add a detailed comments on the user for future help of developers.

Also make sure client onClose is implemented in such a way, so similar leak should not happen.


Note

Medium Risk
Touches core connection/client close paths and hook invocation semantics, which could affect cleanup ordering and error propagation. The change is well-contained and reinforced by extensive new regression/concurrency tests.

Overview
Fixes a resource leak caused by repeatedly wrapping baseClient close logic (issue #3772) by replacing the single onClose func() error with a bounded, concurrency-safe onCloseHooks registry where re-registering the same hook id replaces the prior callback.

Moves streaming-credentials unsubscription from client-level close hooks to per-connection pool.Conn.SetOnClose, and documents the required idempotent semantics for StreamingCredentialsProvider.Subscribe/UnsubscribeFunc to avoid leaks across connection re-inits.

Updates sentinel failover and ring-shard cleanup to use the new named-hook registry, and adds focused tests covering hook ordering/replacement/error handling/concurrency plus a regression test modeling EntraID-style providers.

Reviewed by Cursor Bugbot for commit a337f4b. Bugbot is set up for automated code reviews on this repo. Configure here.

@jit-ci
Copy link
Copy Markdown

jit-ci Bot commented Apr 22, 2026

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

@ndyakov ndyakov merged commit 00a551b into master Apr 22, 2026
67 of 69 checks passed
@ndyakov ndyakov deleted the ndyakov/fix-onClose branch April 22, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak: wrappedOnClose builds unbounded closure chain per initConn when using StreamingCredentialsProvider

2 participants