Skip to content

refactor(pool): use asyncband for all semaphore backends - #4404

Open
tisonkun wants to merge 1 commit into
transact-rs:mainfrom
tisonkun:codex/asyncband-semaphore
Open

refactor(pool): use asyncband for all semaphore backends#4404
tisonkun wants to merge 1 commit into
transact-rs:mainfrom
tisonkun:codex/asyncband-semaphore

Conversation

@tisonkun

@tisonkun tisonkun commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Does your PR solve an issue?

Partially addresses #1668 by removing futures-intrusive from sqlx-core. sqlx-sqlite still uses its mutex, so this does not close that issue.

Use asyncband 0.7.1's fair semaphore for every runtime, replacing both the Tokio and futures-intrusive implementations of AsyncSemaphore. Keep the pool's existing permit ownership, manual release, and close-event protocol while removing the runtime-specific adapter branches and the non-fair benchmarking option.

Is this a breaking change?

No change to the supported SQLx API or its FIFO pool-acquisition contract. There are implementation-level changes to review:

  • Remove the doc-hidden, benchmarking-only PoolOptions::__fair method and the fair argument of sqlx-core::sync::AsyncSemaphore::new. The sqlx-core API is explicitly SemVer-exempt.
  • Pool semaphore operations no longer emit Tokio semaphore resource events for tokio-console or participate in Tokio's cooperative polling budget through the semaphore.

Validation

Added deterministic pool tests for FIFO acquisition after waiter cancellation, closing while connections remain checked out (including cancellation of a partially satisfied multi-permit acquisition), and returning child-pool permits to the parent.

  • SQLite-backed any-pool tests on Tokio, smol, async-global-executor, and async-std: 6 passed and 1 existing ignored test for each runtime.
  • Existing sqlite integration tests on Tokio and smol: 44 passed and 1 existing ignored test for each runtime.
  • cargo test -p sqlx-core --all-features: 7 unit tests and 30 doc tests passed; 31 doc tests ignored.
  • cargo clippy -p sqlx-core --all-targets --all-features -- -D warnings
  • cargo check -p sqlx-core --no-default-features
  • cargo fmt --all -- --check

An additional Clippy check of the any-pool test target encounters an existing needless_question_mark warning in unchanged sqlx-test/src/lib.rs:20. It passes with only that lint allowed (-D warnings -A clippy::needless_question_mark).

AI assisted with the implementation, tests, and PR draft.

@tisonkun
tisonkun marked this pull request as ready for review September 8, 2026 08:28
@tisonkun

tisonkun commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Background:

This Semaphore is always fair and does not integrate with tokio-console's traces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant