Skip to content

fix: bind InternalRPC and heartbeat tasks to the provided runtime#454

Open
PopClom wants to merge 3 commits intoamqp-rs:mainfrom
PopClom:fix-runtime
Open

fix: bind InternalRPC and heartbeat tasks to the provided runtime#454
PopClom wants to merge 3 commits intoamqp-rs:mainfrom
PopClom:fix-runtime

Conversation

@PopClom
Copy link

@PopClom PopClom commented Mar 16, 2026

connect_uri_with_runtime accepts an explicit runtime, but InternalRPC::run and the heartbeat task are spawned via async_rs's runtime.spawn(), which checks Handle::try_current() before the stored handle. Since the runtime is typically constructed via tokio_current() — which captures a Handle but does not hold an owned TokioRTself.runtime is None, and try_current() always wins when called from an async context, ignoring the handle that was explicitly provided.

When the caller's runtime has a shorter lifetime than the connection — e.g. a #[tokio::test] runtime sharing a connection pool across tests — InternalRPC::run dies when the test ends, silently breaking publish confirmations.

Fix: bump async-rs to 0.8.2, which checks the stored handle before Handle::try_current().

@Keruspe
Copy link
Collaborator

Keruspe commented Mar 16, 2026

Nice catch, thanks!

I'd rather keep the internal_rpc start where it is though and not add more not-really-related things to the io loop.
This brought to light a bug in async-rs though, which is now fixed in 0.8.2.

Could you drop the move to io_loop; keep your test and bump the dependency of async-rs to 0.8.2 to confirm everything is ok this way?

@PopClom
Copy link
Author

PopClom commented Mar 16, 2026

Makes sense, thanks! Bumped async-rs to 0.8.2 and the test passes with just that change 🙌

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.

2 participants