Repository navigation
fix(telemetry): flush shared client on final release - #413
Conversation
Signed-off-by: Jay Xiao <jay.xiao@databricks.com>
d665658 to
0eb5058
Compare
Signed-off-by: Jay Xiao <jay.xiao@databricks.com>
There was a problem hiding this comment.
Verdict: 2 Low
Looks good — the session-vs-lease split correctly defers the bounded close-flush to the last active-session release while keeping the shared client open (and its timer running) until all statement/result-stream observers drop, and moving the timer/flush/drop tasks onto a dedicated, session-independent telemetry runtime is the right fix for cross-runtime shutdown. Logic traced clean across the explicit-release, drop-only, mixed, and late-observer paths with no underflow or lost-flush windows; tests are deterministic. Two non-blocking low notes: the switch from saturating_sub to plain -= removes the release-build safety net against a hypothetical count regression (which would leak a host client), and the single-worker shared runtime now funnels all hosts' exports through one thread.
Addresses: - #4393136816 at src/telemetry/manager.rs:106 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — a solid, well-tested lifecycle change. The session_count/lease_count split correctly keeps the shared per-host client open (scheduled + batch exports continue) until the final session closes, with a bounded close-time flush, while surviving observer leases keep the client alive for late events; the session_released AcqRel swap makes release()/Drop idempotent and prevents double-decrement, and moving the timer/batch/cleanup onto an independent telemetry runtime fixes the creator-runtime-shutdown and drop-outside-Tokio cases (both covered by new tests). One low-severity note inline about permanent caching of a runtime-build failure.
Addresses: - #4397313433 at src/telemetry/client.rs:188 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
| if let Some(runtime) = runtime.as_ref() { | ||
| return Ok(runtime.handle().clone()); | ||
| } | ||
| let built = tokio::runtime::Builder::new_multi_thread() |
There was a problem hiding this comment.
The new runtime omits thread_stack_size, so its worker inherits RUST_MIN_STACK. With RUST_MIN_STACK=16384, a real HTTP telemetry export causes stack overflow in dbx-sql-telemetry and aborts the process. The C ABI runtime already guards against this. Apply the same 2 MiB minimum here, preserving larger configured values.
There was a problem hiding this comment.
Both clean. The fix is complete and verified.
Pushed b205bd5.
Addresses: - #4416139377 at src/telemetry/client.rs:198 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — the session/observer ref-count split (session_count vs lease_count), the final-release flush gating, and the dedicated static telemetry runtime are correct, idempotent, and well-covered by the new tests; each count is decremented exactly once per lease with no double-decrement or missed/duplicated flush, and the runtime is only handle()-cloned (never block_on'd) so building it inside another runtime is safe. One low-severity maintainability note about duplicated stack-floor logic. No nits.
Addresses: - #4416331193 at src/telemetry/client.rs:189 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: 1 Low
The PR looks correct: tracking open sessions and live leases separately is sound, and the drop-time action matrix (none / flush / close) holds up against the new tests. One low-severity concern is left. Exports now run on a separate telemetry runtime but still use the creating session's pooled HTTP client, which may fail after a session-owned runtime shuts down.
| return Ok(runtime.handle().clone()); | ||
| } | ||
| let built = tokio::runtime::Builder::new_multi_thread() | ||
| .worker_threads(1) |
There was a problem hiding this comment.
🔵 Low — Exports now always run on the dedicated dbx-sql-telemetry runtime, but they still go through the creating session's pooled reqwest::Client. The cached per-host client keeps that first exporter even after the creating session has closed. Hyper's connection-driver tasks run on whichever runtime opened the connection. So one pool now holds connections driven by the session runtime (query traffic) next to connections driven by the telemetry runtime, and telemetry and queries hit the same host. Once a session-owned runtime shuts down (the timer_survives_creator_session_runtime_shutdown scenario), a telemetry export can check out a pooled connection whose driver task is gone. That is the known reqwest/hyper "dispatch task is gone" failure. A batch that fails this way is silently dropped, and repeated failures can trip the circuit breaker. I couldn't confirm the failure end to end. Two possible fixes: give the telemetry exporter its own HTTP client built on the telemetry runtime, or add a test where the creator runtime has made a real pooled request before it is dropped.
There was a problem hiding this comment.
Applied the fix locally but the push failed (likely another commit landed on this branch since I started). This bundle covered 1 thread(s); all reverted. Re-trigger by replying to this thread.
[push retry after rebase failed]
- A pull request for this branch has been added to a merge queue. Branches that
remote: are queued for merging cannot be updated. To modify this branch, dequeue the
remote: associated pull request.
To https://github.com/databricks/databricks-sql-kernel.git
! [remote rejected] jay/telemetry-flush-last-client -> jay/telemetry-flush-last-client (protected branch hook declined)
error: failed to push some refs to 'https://github.com/databricks/databricks-sql-kernel.git'
There was a problem hiding this comment.
Thanks for trying the fix. The push was rejected because the PR is in the merge queue, so nothing on the branch has changed, and the current code still sends exports through the creating session's pooled client. The finding is still open. Someone will need to apply the change by hand, either after taking the PR out of the queue or in a follow-up PR. The change is to give the telemetry exporter its own HTTP client built on the dbx-sql-telemetry runtime, or to add a test where the creator runtime makes a real pooled request before it's dropped.
There was a problem hiding this comment.
⛔ NEEDS HUMAN DECISION — the bots can't resolve this thread; a maintainer's input is required.
I agree with the finding: telemetry exports should not share the creating session's pooled reqwest::Client, whose connections can be driven by a session runtime that has since shut down. But I can't apply the fix in this PR. The branch is in the merge queue, and the earlier push was rejected with "Branches that are queued for merging cannot be updated". A human needs to either take the PR out of the queue and re-trigger me, or make the change in a follow-up PR. The change is to give the telemetry exporter its own HTTP client built on the dbx-sql-telemetry runtime, plus an offline wiremock test where the creator runtime makes a real pooled request before it is dropped and a later export still succeeds.
Summary
The close path forces a telemetry flush only when no active session remains for the host. Scheduled and batch-size exports continue while sessions are active so the queue stays bounded.
Scope
The earlier crypto dependency downgrade has been removed from this PR. Security Scan and advisory findings in the current
maindependency graph are separate from this telemetry change.Validation
cargo testcargo clippy --all-targets -- -D warningscargo +stable fmt --all -- --checkcargo check --lockedinpyo3/andnapi/