voelin-platform: zbus on async-io alone in every binary (notify-rust z), and a test for the order of ashpd's callers
ashpd 0.13.13 keeps one session connection per process (a static in its
proxy.rs), and zbus 5.19 picks that connection's executor once, from
Handle::try_current() on the thread that builds it, when both its `tokio` and
`async-io` features are compiled in. The first ashpd caller therefore decided
the executor of every later portal call: a tokio caller first, then a caller
with no runtime (a GPUI foreground task), panics with "there is no reactor
running" (get_property("version") sets up zbus's property cache, which calls
tokio::task::spawn). The merged binary was safe only because GPUI's
colour-scheme call builds the connection before the engine's portal calls.
voelin-platform's notify-rust asks for `z` (async-io) in place of
`z-with-tokio`, and the stand-in portal's zbus dev-dependency for `async-io`
instead of `tokio`: a test binary with both features shows the panic even when
the binaries do not have it. `cargo tree -e features -i zbus` now names
`tokio` nowhere; Cargo.lock loses zbus's tokio edge and tokio's tracing edge
(THIRD_PARTY_NOTICES.md is unchanged).
tests/proxy.rs gets the gate's probe shape on a private dbus-run-session bus
(skipped with a printed reason where none can be made): a tokio caller first,
then a caller with no runtime. It fails with the panic on the tree before this
change, and still did with only notify-rust moved, which is why the
dev-dependency moved too.
The four records that described the move wrongly are corrected:
docs/design/gpui-spikes.md "Dependencies", the comment of
PortalCapture::start, voelin-media's Cargo.toml and CHANGELOG.md (whose
Slint-only sentence goes: the Slint app's zbus connections move to async-io
threads too).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3f4dc700af
commit
ed49c283a2
7 files changed
+102
-45
No files matched your search
@@ -71,8 +71,10 @@ yuv = "0.8.19"
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
# `async-io`, not `tokio`: GPUI's Linux backend enables ashpd's `async-io`, ashpd
|
||||
# refuses both at once, and a front end holds the portals and GPUI in one binary.
|
||||
# zbus then runs a connection on its own I/O thread, or on tokio when it is made
|
||||
# inside a tokio runtime and another crate turns zbus's `tokio` feature on.
|
||||
# zbus then runs every connection on an I/O thread of its own, whichever thread
|
||||
# builds it: no crate of the workspace turns zbus's `tokio` feature on (with it
|
||||
# zbus would pick tokio for a connection made inside a tokio runtime, and ashpd
|
||||
# shares one connection per process with every later caller).
|
||||
ashpd = { version = "0.13.13", default-features = false, features = ["camera", "screencast", "async-io"], optional = true }
|
||||
memmap2 = { version = "0.9.11", optional = true }
|
||||
pipewire = { version = "0.10.1", optional = true }
|
||||
|
||||
@@ -181,9 +181,9 @@ impl ScreenCapture for PortalCapture {
|
||||
}
|
||||
|
||||
/// Asks the user through the portal dialog (unless a restore token
|
||||
/// applies). Any executor will do: ashpd runs on zbus's `async-io`, whose
|
||||
/// connection has an I/O thread of its own (inside a tokio runtime, with
|
||||
/// zbus's `tokio` feature on as well, it runs on tokio instead).
|
||||
/// applies). Any executor will do: ashpd runs on zbus's `async-io` in every
|
||||
/// binary of the workspace (no crate turns zbus's `tokio` feature on), whose
|
||||
/// connection has an I/O thread of its own, whichever thread builds it.
|
||||
fn start(
|
||||
&mut self,
|
||||
source: &SourceId,
|
||||
|
||||
@@ -28,7 +28,7 @@ tracing = "0.1"
|
||||
# ashpd refuses both features at once.
|
||||
ashpd = { version = "0.13", default-features = false, features = ["async-io", "global_shortcuts", "file_chooser", "proxy_resolver"], optional = true }
|
||||
futures-util = { version = "0.3", optional = true }
|
||||
notify-rust = { version = "4.18", default-features = false, features = ["z-with-tokio"] }
|
||||
notify-rust = { version = "4.18", default-features = false, features = ["z"] }
|
||||
x11rb = { version = "0.13", features = ["xinput"], optional = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
@@ -48,8 +48,11 @@ tokio = { version = "1", features = ["macros", "rt-multi-thread", "time"] }
|
||||
[target.'cfg(all(unix, not(target_os = "macos")))'.dev-dependencies]
|
||||
x11rb = { version = "0.13", features = ["xinput", "xtest"] }
|
||||
# A stand-in desktop portal on a private session bus (tests/proxy.rs); the
|
||||
# zbus ashpd uses.
|
||||
zbus = { version = "5", default-features = false, features = ["tokio"] }
|
||||
# zbus ashpd uses, on `async-io` like every other zbus in the workspace: a
|
||||
# `tokio` here would put the executor choice of ashpd's connection (zbus picks
|
||||
# tokio when a tokio runtime is current where it builds the connection) into
|
||||
# the tests alone, and tests/proxy.rs checks that the choice does not matter.
|
||||
zbus = { version = "5", default-features = false, features = ["async-io"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
@@ -6,9 +6,10 @@
|
||||
//! or a bus daemon for it, the test says so and checks nothing. Its own test
|
||||
//! binary: answers are kept process-wide.
|
||||
//!
|
||||
//! The second test calls ashpd from a thread with no tokio runtime, as GPUI's
|
||||
//! executor would: ashpd runs on zbus's `async-io` there (docs/design/gpui-spikes.md,
|
||||
//! "Dependencies").
|
||||
//! The second and third tests call ashpd from a thread with no tokio runtime,
|
||||
//! as GPUI's executor would: ashpd runs on zbus's `async-io`, whichever thread
|
||||
//! built its connection (the third lets a tokio caller build it first;
|
||||
//! docs/design/gpui-spikes.md, "Dependencies").
|
||||
|
||||
#![cfg(all(unix, not(target_os = "macos"), feature = "portal"))]
|
||||
|
||||
@@ -158,6 +159,38 @@ fn block_on<F: std::future::Future>(future: F) -> F::Output {
|
||||
}
|
||||
}
|
||||
|
||||
/// The stand-in portal on the bus of its own, served from the calling task.
|
||||
async fn stand_in_portal(lookups: &Arc<AtomicU32>) -> zbus::Connection {
|
||||
zbus::connection::Builder::session()
|
||||
.unwrap()
|
||||
.name("org.freedesktop.portal.Desktop")
|
||||
.unwrap()
|
||||
.serve_at("/org/freedesktop/portal/desktop", Resolver { lookups: lookups.clone() })
|
||||
.unwrap()
|
||||
.build()
|
||||
.await
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// A lookup through ashpd, from the calling task.
|
||||
async fn lookup() -> Vec<ashpd::Uri> {
|
||||
let resolver = ashpd::desktop::proxy_resolver::ProxyResolver::new().await.unwrap();
|
||||
let uri = ashpd::Uri::parse("https://capped.example/").unwrap();
|
||||
resolver.lookup(&uri).await.unwrap()
|
||||
}
|
||||
|
||||
/// A lookup through ashpd from a thread of its own with no runtime, blocking
|
||||
/// the caller's task for it (the pool's threads, `spawn_blocking`, have the
|
||||
/// runtime in reach). The stand-in portal runs on the test's runtime: keep it
|
||||
/// free while waiting.
|
||||
async fn lookup_without_a_runtime() -> Vec<String> {
|
||||
let caller = std::thread::spawn(|| {
|
||||
assert!(tokio::runtime::Handle::try_current().is_err(), "this thread has no runtime");
|
||||
block_on(lookup()).iter().map(|uri| uri.as_str().to_owned()).collect::<Vec<_>>()
|
||||
});
|
||||
tokio::task::spawn_blocking(move || caller.join().unwrap()).await.unwrap()
|
||||
}
|
||||
|
||||
/// ashpd with `async-io`: a caller outside any tokio runtime gets its answer,
|
||||
/// the connection's I/O running on zbus's own thread.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
@@ -168,28 +201,33 @@ async fn the_portal_answers_a_caller_without_a_runtime() {
|
||||
return;
|
||||
}
|
||||
let lookups = Arc::new(AtomicU32::new(0));
|
||||
let _portal = zbus::connection::Builder::session()
|
||||
.unwrap()
|
||||
.name("org.freedesktop.portal.Desktop")
|
||||
.unwrap()
|
||||
.serve_at("/org/freedesktop/portal/desktop", Resolver { lookups: lookups.clone() })
|
||||
.unwrap()
|
||||
.build()
|
||||
.await
|
||||
.unwrap();
|
||||
// A thread of its own: the pool's threads (`spawn_blocking`) have the
|
||||
// runtime in reach.
|
||||
let caller = std::thread::spawn(|| {
|
||||
assert!(tokio::runtime::Handle::try_current().is_err(), "this thread has no runtime");
|
||||
block_on(async {
|
||||
let resolver = ashpd::desktop::proxy_resolver::ProxyResolver::new().await.unwrap();
|
||||
let uri = ashpd::Uri::parse("https://capped.example/").unwrap();
|
||||
resolver.lookup(&uri).await.unwrap()
|
||||
})
|
||||
});
|
||||
// The stand-in portal runs on this runtime: keep it free while waiting.
|
||||
let answer = tokio::task::spawn_blocking(move || caller.join().unwrap()).await.unwrap();
|
||||
let answer: Vec<&str> = answer.iter().map(|uri| uri.as_str()).collect();
|
||||
assert_eq!(answer, ["socks://127.0.0.1:2080"]);
|
||||
let _portal = stand_in_portal(&lookups).await;
|
||||
assert_eq!(lookup_without_a_runtime().await, ["socks://127.0.0.1:2080"]);
|
||||
assert_eq!(lookups.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
/// ashpd keeps one session connection for the process, and zbus picks the
|
||||
/// executor of a connection once, when it builds it: tokio if a tokio runtime
|
||||
/// is current on that thread and zbus has its `tokio` feature on, its own
|
||||
/// `async-io` thread otherwise. If the engine's runtime made the connection
|
||||
/// first, a later caller with no runtime (a GPUI foreground task) would find a
|
||||
/// tokio connection with no reactor to run on and panic ("there is no reactor
|
||||
/// running" in zbus's property cache). With zbus on `async-io` alone in every
|
||||
/// binary (notify-rust without `z-with-tokio`, no zbus `tokio` here either)
|
||||
/// the order does not matter.
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
async fn the_portal_answers_a_caller_without_a_runtime_after_a_tokio_caller() {
|
||||
const TEST: &str = "the_portal_answers_a_caller_without_a_runtime_after_a_tokio_caller";
|
||||
if std::env::var_os(ON_ITS_OWN_BUS).is_none() {
|
||||
on_a_bus_of_its_own(TEST);
|
||||
return;
|
||||
}
|
||||
let lookups = Arc::new(AtomicU32::new(0));
|
||||
let _portal = stand_in_portal(&lookups).await;
|
||||
// The tokio caller first: it builds the process's session connection.
|
||||
let answer: Vec<_> = lookup().await.iter().map(|uri| uri.as_str().to_owned()).collect();
|
||||
assert_eq!(answer, ["socks://127.0.0.1:2080"]);
|
||||
// Then the caller with no runtime, on the same connection.
|
||||
assert_eq!(lookup_without_a_runtime().await, ["socks://127.0.0.1:2080"]);
|
||||
assert_eq!(lookups.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
Reference in new issue
Block a user