Skip to content

Conversation

@martin-kolarik
Copy link
Contributor

async-global-executor added as the fourth executor. The PR extends PR #3790.

This is a breaking change -- async-global-executor has MSRV 1.80, therefore sqlx will have to be upgraded too.

@abonander
Copy link
Collaborator

I would prefer to deprecate async-std for a release cycle before deleting it. Just cause it's discontinued doesn't mean people will stop using it immediately, especially because its constituent crates will continue to receive updates.

@martin-kolarik
Copy link
Contributor Author

I would prefer to deprecate async-std for a release cycle before deleting it. Just cause it's discontinued doesn't mean people will stop using it immediately, especially because its constituent crates will continue to receive updates.

Sure, I did not remove async_std from the sources, for the same reason.

@abonander abonander added the breaking:MSRV Requires waiting for an MSRV bump (see FAQ.md) label Apr 11, 2025
Copy link
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

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

Same note as here: #3790 (review)

@martin-kolarik martin-kolarik force-pushed the smol+async-global-executor-1.80-dev branch from 1f43f07 to 8d6377b Compare April 13, 2025 11:39
@martin-kolarik martin-kolarik force-pushed the smol+async-global-executor-1.80-dev branch from 8c2c83c to 9b0cebb Compare April 13, 2025 13:50
@martin-kolarik martin-kolarik force-pushed the smol+async-global-executor-1.80-dev branch from 35237ac to c3e8f61 Compare April 13, 2025 14:24
@abonander
Copy link
Collaborator

@martin-kolarik do you plan on addressing the CI failure and merge conflicts?

@martin-kolarik
Copy link
Contributor Author

@martin-kolarik do you plan on addressing the CI failure and merge conflicts?

I would like to address both. I will look at merge conflict first (today or on Monday) and we will see how tests changed. CI failure is linked to changes around to_socket_addrs and I suspect tests fail due to changed behavior. I will write more later.

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	rust-toolchain.toml
#	sqlx-cli/Cargo.toml
#	sqlx-core/Cargo.toml
#	sqlx-core/src/rt/mod.rs
#	sqlx-macros-core/src/lib.rs
#	sqlx-sqlite/src/connection/worker.rs
@martin-kolarik
Copy link
Contributor Author

So, merged, fixed, and tests are running: the main issue of previous failures disappeared by itself, there certificate for localhost was expected.

CI completion is prevented with error in build using minimal versions check, where async-fs fails. According to rust-lang/cargo#5657 it may happen. Did you have similar issues in the past? How to fix it?

@abonander
Copy link
Collaborator

abonander commented Jul 7, 2025

Strictly speaking, this is a bug in async-fs 2.0.0 because they're calling futures_lite::FutureExt::poll() which did not exist yet in the version they actually specify (1.2).

The whole idea of the minimal-versions test is to make sure that SQLx still builds if someone hasn't updated some arbitrary dependency below it in the tree, so the test is working as expected here. However, this isn't strictly our problem to begin with.

We could switch to -Z minimal-direct-versions which only lowers our direct dependencies to their minimum specified versions, so we'd only be testing our own specifications. This gives limits the scope to dependencies we actually control, but also weakens the guarantees of the minimal-versions check (since indirect dependencies could still be technically broken).

I'd really like feedback from @iamjpotts here since he's the one who recommended adding the check to begin with (#3340).

@iamjpotts
Copy link
Contributor

The whole idea of the minimal-versions test is to make sure that SQLx still builds if someone hasn't updated some arbitrary dependency below it in the tree, so the test is working as expected here. However, this isn't strictly our problem to begin with.

Yes, it is intended to be a correctness check on the declared minimums.

From that standpoint the ci check is working as designed. The original issue was mentioned in #3118 (linked from #3340).

async-fs fixed their dependency declaration in async-fs 2.1.

smol requires futures-lite 2.0, but in sqlx is optional.

The fix is likely to be adding an explicit dependency on a transitive dependency, where the explicit dependency enforces the correct minimum. Possible workarounds to explore:

  • Add a sqlx dependency on async-fs 2.1
  • Add a sqlx dependency on futures-lite 2.0

For either it would be a good idea to add a comment that the above is to resolve a problem with a transitive dependency (and which one, idk if it is smol without further investigation)

Try to fix CI -Z minimal-versions check
@martin-kolarik
Copy link
Contributor Author

  • Add a sqlx dependency on async-fs 2.1
  • Add a sqlx dependency on futures-lite 2.0

I added dependency on async-fs 2.1, as it imo better describes the intention of the workaround: the async-fs 2.0 contains bug, not futures-lite.

@iamjpotts
Copy link
Contributor

  • Add a sqlx dependency on async-fs 2.1
  • Add a sqlx dependency on futures-lite 2.0

I added dependency on async-fs 2.1, as it imo better describes the intention of the workaround: the async-fs 2.0 contains bug, not futures-lite.

This specific change lgtm though @abonander may have more fine grained feedback.

}

panic!("either the `runtime-async-std` or `runtime-tokio` feature must be enabled")
panic!("one of the `runtime-async-global-executor`, `runtime-async-std`, `runtime-smol`, or `runtime-tokio` feature must be enabled")
Copy link
Contributor

Choose a reason for hiding this comment

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

Grammar - should be features

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, should I change PR?

// Work around `impl Socket`` and 'unability to specify test build cargo feature'.
// `connect_tcp_address` compilation would fail without this impl with
// 'cannot infer return type' error.
impl Socket for () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Were any alternatives to this considered?

Why is this unreachable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

impl Socket for () satisfies Rust type system, it is necessary at @260, when neither _rt-tokio nor _rt-async-io is selected. rustc cannot resolve impl Socket type without defining any. Also that's why the impl uses unreachable!, it is erased and unused during runtime.

The code has been added after discussing it in #3790 (comment), where shared implementation for both executors to resolve host names was suggested. I think it is fine, but it ended with impl Socket issue.

IMO there is alternative to use enum on connect_tcp_address return, but I expect it would bubble up through connect_tcp, which also has generic output, so enum would appear in many places. Using void impl on unit type seemed better to me.


Ok(stream)
} else {
crate::rt::missing_rt(socket_addr)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually a breaking behavior change. The existing behavior is to fall back to async_io if a Tokio runtime isn't available, which could be important for some use-cases.

Because of Cargo's feature unification, if a library using SQLx turns on the runtime-tokio feature, it's forced on for users of that library as well, whether they want it or not. The only way to turn it off is to patch the library.

This change would make a situation like that a hard blocker instead of mildly annoying.

@abonander
Copy link
Collaborator

I'm going to merge to avoid the need for any more back-and-forth, but I'm going to be making some adjustments in a follow-up PR.

@abonander abonander merged commit 6b828e6 into launchbadge:main Sep 8, 2025
144 checks passed
@martin-kolarik
Copy link
Contributor Author

I'm going to merge to avoid the need for any more back-and-forth, but I'm going to be making some adjustments in a follow-up PR.

Thank you, unfortunately I was off during weekend so I did not respond to breaking change note. Feel free to ask for anything to be completed.

abonander added a commit that referenced this pull request Sep 8, 2025
* restore fallback to `async-io` for `connect_tcp()` when `runtime-tokio` feature is enabled
* `smol` and `async-global-executor` both use `async-task`, so `JoinHandle` impls can be consolidated
* no need for duplicate `yield_now()` impls
* delete `impl Socket for ()`
abonander added a commit that referenced this pull request Sep 8, 2025
* restore fallback to `async-io` for `connect_tcp()` when `runtime-tokio` feature is enabled
* `smol` and `async-global-executor` both use `async-task`, so `JoinHandle` impls can be consolidated
* no need for duplicate `yield_now()` impls
* delete `impl Socket for ()`
JosiahParry pushed a commit to JosiahParry/sqlx that referenced this pull request Sep 24, 2025
* Sqlx-core: rename async_io dependency for async-std

* Sqlx-core: simplify TimeoutError

* Sqlx-core: code for async-global-executor

* Sqlx: integrate async-global-executor feature

* Note to unsafe

* Step up MSRV as async-global-executor needs it

* Sqlx-core: fix of unix socket build

* Unsafe fixes, smol executor added

* Workflow fix

* Changes outside sqlx_rt

* Cleanup conditional rt compilation

* Warning

* Add executors to test matrix

* Fix of skipping code sqlite due to mismatch in cargo feature names

* Smol executor isolated

* Fix, reduce number of tests, remove async_std

* Fix of test_block_on, regression

* Format fixes

* async-global-executor added

* async-std changed to 1.13

* litemap, zerofrom requires rustc 1.81

* Fix of missing _sqlite in cargo.toml

* Clippy lints

* Clean up

* Remove features combinations

* Fixes after merge

* Fix of compiling connect_tcp_address with both tokio + other executor selected

* Try to fix CI -Z minimal-versions check

Try to fix CI -Z minimal-versions check
JosiahParry pushed a commit to JosiahParry/sqlx that referenced this pull request Sep 24, 2025
* restore fallback to `async-io` for `connect_tcp()` when `runtime-tokio` feature is enabled
* `smol` and `async-global-executor` both use `async-task`, so `JoinHandle` impls can be consolidated
* no need for duplicate `yield_now()` impls
* delete `impl Socket for ()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking:MSRV Requires waiting for an MSRV bump (see FAQ.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants