Skip to content

feat: Graceful session pool shutdown - #623

Open
aral01 wants to merge 6 commits into
masterfrom
graceful-session-pool-shutdown-clean
Open

aral01 wants to merge 6 commits into
masterfrom
graceful-session-pool-shutdown-clean

Conversation

@aral01

@aral01 aral01 commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

  • Session deletion and transaction rollbacks runs in detached tasks, which cannot be awaited.
  • Dropping tokio runtime can abort those tasks

Issue Number: closes #555, related #560

What is the new behavior?

  • Session pool owns CleanupWorker thread
  • Deletions and rollbacks are synchroniously submitted to that worker manually/on drop
  • Upon shutdown Driver awaits all cleanup worker tasks

Other information

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.55656% with 55 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.19%. Comparing base (fe2d450) to head (2aaf693).

Files with missing lines Patch % Lines
ydb/src/session_pool/cleanup_worker.rs 90.10% 29 Missing ⚠️
ydb/src/session_pool/pool.rs 79.52% 26 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #623      +/-   ##
==========================================
+ Coverage   88.12%   88.19%   +0.06%     
==========================================
  Files         202      203       +1     
  Lines       21328    21644     +316     
==========================================
+ Hits        18796    19089     +293     
- Misses       2532     2555      +23     
Flag Coverage Δ
rust-1.88.0 88.17% <87.55%> (+0.04%) ⬆️
rust-1.96.1 88.54% <87.72%> (+0.05%) ⬆️
tests 88.19% <87.55%> (+0.06%) ⬆️
ubuntu 88.19% <87.55%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rekby rekby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK

— 🤖 AI review on behalf of @rekby

@aral01 aral01 changed the title Graceful session pool shutdown clean feat: Graceful session pool shutdown Aug 15, 2026

@rekby rekby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK

— 🤖 AI review on behalf of @rekby

@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from 341aecc to 9f667d2 Compare August 15, 2026 16:42

@rekby rekby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK

— 🤖 AI review on behalf of @rekby

@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from 9f667d2 to 5e45ca9 Compare August 17, 2026 06:55
@aral01 aral01 added the SLO label Aug 17, 2026
@github-actions

Copy link
Copy Markdown

🌋 SLO Test Results

🟢 3 workload(s) tested — All thresholds passed

Commit: b47a2d5 · View run

Workload Thresholds Duration Report
native-topic-tx 🟢 OK 10m 10s 📄 Report
native-topic 🟢 OK 10m 📄 Report
native-query 🟢 OK 10m 1s 📄 Report

Generated by ydb-slo-action

@github-actions github-actions Bot removed the SLO label Aug 17, 2026

@rekby rekby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

— 🤖 AI review on behalf of @rekby

Comment thread ydb/src/client.rs
/// Shutdown must run while the Tokio runtime that created the driver is still alive.
#[instrument(name = "ydb.Driver.Shutdown", skip_all, fields(db.system.name = "ydb", db.namespace = %self.credentials.database), err)]
pub async fn shutdown(self) -> YdbResult<()> {
self.session_pool.shutdown().await

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] This only shuts down the currently configured pool. with_session_pool replaces self.session_pool without shutting down or retaining the previous pool, while query/table clients created before replacement keep clones of that old pool. Consequently, after reconfiguration this method can return while old leases and cleanup tasks are still active, and those older clients can still acquire sessions. That defeats the documented shutdown guarantee and can still lose cleanup when the runtime is dropped. Please include superseded pools in the shutdown lifecycle or shut down the old pool during replacement.

— 🤖 AI review on behalf of @rekby

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This still applies at the current head: with_session_pool replaces the field via Self { session_pool, ..self }, while shutdown only awaits self.session_pool.shutdown(). A previously created QueryClient or TableClient therefore retains an untracked clone of the superseded pool and can keep acquiring sessions after this shutdown returns.

— 🤖 AI review on behalf of @rekby

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still unresolved at f60ecbf: the new commit only bounds cleanup connection acquisition; with_session_pool still replaces the pool, and shutdown still awaits only the replacement. Previously derived clients can therefore retain and use the superseded pool.

— 🤖 AI review on behalf of @rekby

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still unresolved at 97be54b3: with_session_pool still replaces the field with Self { session_pool, ..self }, while shutdown awaits only that replacement. A query/table client created before replacement therefore retains the superseded pool and can continue acquiring sessions after this shutdown completes.

— 🤖 AI review on behalf of @rekby

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still unresolved at ac216fe: this push only changes cleanup timeout coverage. with_session_pool still replaces the pool via Self { session_pool, ..self }, while shutdown awaits only self.session_pool. Query/table clients created before replacement therefore retain the original pool and can still acquire sessions after shutdown returns.

— 🤖 AI review on behalf of @rekby

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Still unresolved at 2aaf6938: with_session_pool continues to replace the field via Self { session_pool, ..self }, while shutdown only awaits the replacement. A query/table client created before replacement therefore retains the superseded pool and can keep acquiring sessions after shutdown returns.

— 🤖 AI review on behalf of @rekby

@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from 5e45ca9 to 0d259af Compare August 24, 2026 11:00
@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from 0d259af to 3b26944 Compare August 24, 2026 19:44

@rekby rekby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK

— 🤖 AI review on behalf of @rekby

@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from 3b26944 to f60ecbf Compare August 25, 2026 13:29
@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from f60ecbf to 97be54b Compare August 26, 2026 09:59
@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from 97be54b to ac216fe Compare August 26, 2026 11:33
Base automatically changed from refactor/query-transaction-lifetime to master August 26, 2026 14:28
aral01 added 4 commits August 26, 2026 17:28
Centralize best-effort DeleteSession execution in a pool-owned worker. Session drops submit cleanup commands, while the worker executes accepted deletions concurrently and drains them when its channel closes.
@aral01
aral01 force-pushed the graceful-session-pool-shutdown-clean branch from ac216fe to 2aaf693 Compare August 26, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants