Repository navigation
fix(auth): hold the HTTP client weakly in OAuth providers - #435
Conversation
`DatabricksHttpClient` owns its auth provider, and the M2M, M2M private-key and U2M providers (and the Azure service principal provider built on M2M) each held a strong `Arc<DatabricksHttpClient>` back to it. The pair formed a reference cycle, so closing an OAuth session leaked the HTTP client, the provider and the tokio runtime handle the provider captures. In the Python binding, which runs one runtime per session, that handle keeps the runtime's FDs open, the same symptom as the transport cycle fixed in #434. The providers now store a `Weak` and upgrade it only when a token fetch runs, matching `FederationProvider`. Their constructors take `&Arc<DatabricksHttpClient>` so the caller keeps ownership, and a shared `upgrade_http_client` helper replaces federation's inline upgrade. Signed-off-by: cathleeny <58714163+cathleeny@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
Resolve the NEXT_CHANGELOG.md conflict by keeping both Fixed entries. Signed-off-by: cathleeny <58714163+cathleeny@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 High
The fix itself looks correct: holding the client weakly breaks the client↔provider cycle for M2M, JWT, U2M and Azure SP, and the new tests cover it. One medium concern: the public constructor signatures and their semantics change on a 1.x crate.
Label the constructor signature change as a Rust API break, as v1.2.0 did for TelemetryConfig::enabled, and note the invalid_state error after the client is dropped. Signed-off-by: cathleeny <58714163+cathleeny@users.noreply.github.com> Co-authored-by: Isaac <no-reply@databricks.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low · 1 Nit
Looks good, with 1 low concern. Switching the providers to Weak breaks the client↔provider cycle the same way FederationProvider does. The cached-token path never upgrades the client, and every caller in the crate has been updated to the new &Arc signatures.
This overview is Claude Opus 5.5's initial take; GPT-6.1 Sol added findings it doesn't mention — see the findings below.
Other findings
- ⚪ Nit — The test asserts only the message substring, though the changelog promises an
invalid_stateerror. Add an assertion onerr.codebeing the invalid-state code. (Found by Claude Opus 5.5 · confirmed by the judge)
The changelog promises a token fetch after the client is dropped fails with invalid_state; check the error code, not only the message. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: cathleeny <58714163+cathleeny@users.noreply.github.com>
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Medium
Looks good, with 1 medium concern. Holding the client through a Weak breaks the cycle. Upgrades happen only inside the refresh closures, so cached-token lookups never touch the client, and the new tests check that both objects are freed. The one concern is that the public constructor signatures changed in a 1.x crate.
Bug: Closing an OAuth session never freed its HTTP client.
DatabricksHttpClientowns its auth provider, and the M2M, M2M private-key and U2M providers (plus the Azure service principal provider built on M2M) each held a strongArc<DatabricksHttpClient>back to it. Runs into the same issueToo many open filesas ES-2348909, and #434 alone does not fix it for OAuth.Changes:
Weakand upgrade it only when a token fetch actually runs, matchingFederationProvider.Testing
provider_does_not_retain_http_clienttests for M2M, JWT M2M and U2M: install the provider on a client, drop the client, and assert both are freed.get_auth_headerreturns an error instead of panicking./proc/self/fd. With only fix(session): free the transport when a session closes #434, FDs grew by 120 (60 epoll, 30 eventfd, 30 socket). With fix(session): free the transport when a session closes #434 and this PR together they grew by 0, and PAT sessions stayed at 0.cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass locally on Rust 1.97.1.