Skip to content

Commit 440e8c3

Browse files
fix(host): spurrious higher ranked lifetime error
A seemingly spurrious higher-ranked lifetime error is being generated on Rust 1.75.0 in wasmbus while launching the provider task. As this code compiled just fine prior to Rust 1.75.0 (released 2023/12/21), this seems to be a spurrious error, for which there is some tracking upstream: rust-lang/rust#110338 Assuming this error *is* spurrious, we can shuffle the work via `tokio::task::spawn_blocking` to avoid the error, causing the work that was going to be done in a distinct thread. This commit fixes a higher-ranked lifetime error by using tokio to force execution on a separate thread which seemingly recalculates lifetimes due to the the synchronous move closure. Signed-off-by: Victor Adossi <[email protected]>
1 parent bd2ec09 commit 440e8c3

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

crates/host/src/wasmbus/mod.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3372,29 +3372,39 @@ impl Host {
33723372
info!(provider_ref, link_name, "handling launch provider"); // Log at info since launching providers can take a while
33733373

33743374
let host_id = host_id.to_string();
3375-
spawn(async move {
3376-
if let Err(err) = self
3377-
.handle_launch_provider_task(
3378-
configuration,
3379-
&link_name,
3380-
&provider_ref,
3381-
annotations.unwrap_or_default(),
3382-
&host_id,
3383-
)
3384-
.await
3385-
{
3386-
error!(provider_ref, link_name, ?err, "failed to launch provider");
3375+
3376+
// Rust 1.75.0 seems to trigger a bogus higher-ranked lifetime error
3377+
// when using tokio::task::spawn here -- using `spawn_blocking` avoids this particular issue.
3378+
//
3379+
// To avoid the higher ranked lifetime error we use spawn_blocking
3380+
// which will move the closure to another blocking-allowed thread,
3381+
// then execute.
3382+
tokio::task::spawn_blocking(move || {
3383+
tokio::runtime::Handle::current().block_on(async move {
33873384
if let Err(err) = self
3388-
.publish_event(
3389-
"provider_start_failed",
3390-
event::provider_start_failed(provider_ref, link_name, &err),
3385+
.handle_launch_provider_task(
3386+
configuration,
3387+
&link_name,
3388+
&provider_ref,
3389+
annotations.unwrap_or_default(),
3390+
&host_id,
33913391
)
33923392
.await
33933393
{
3394-
error!(?err, "failed to publish provider_start_failed event");
3394+
error!(provider_ref, link_name, ?err, "failed to launch provider");
3395+
if let Err(err) = self
3396+
.publish_event(
3397+
"provider_start_failed",
3398+
event::provider_start_failed(provider_ref, link_name, &err),
3399+
)
3400+
.await
3401+
{
3402+
error!(?err, "failed to publish provider_start_failed event");
3403+
}
33953404
}
3396-
}
3405+
})
33973406
});
3407+
33983408
Ok(ACCEPTED.into())
33993409
}
34003410

0 commit comments

Comments
 (0)