Skip to content

fix(runtime): set CURRENT_RUNTIME in Runtime::run() - #952

Closed
paddor wants to merge 2 commits into
compio-rs:masterfrom
paddor:fix/runtime-run-tls
Closed

fix(runtime): set CURRENT_RUNTIME in Runtime::run()#952
paddor wants to merge 2 commits into
compio-rs:masterfrom
paddor:fix/runtime-run-tls

Conversation

@paddor

@paddor paddor commented Jun 14, 2026

Copy link
Copy Markdown
Contributor
  • Runtime::run() calls self.executor.tick() without self.enter(), so CURRENT_RUNTIME is not set during task execution
  • Any task polled or dropped during tick() that calls Runtime::with_current() (e.g. TimerFuture::poll, TimerFuture::drop) panics with "not in a compio runtime"
  • Wrap tick() in self.enter() to match what block_on() and Runtime::drop() already do
  • Add regression test that wakes a timer-holding task after block_on() returns and ticks it via run()
  • Also fix missing futures-util "io" feature needed for PollFd's AsyncRead/AsyncWrite impls (same as fix(runtime): features of futures-util #951)

PollFd implements futures_util::AsyncRead and AsyncWrite, which
require the "io" feature on futures-util. Without it, compio-runtime
fails to compile.
@github-actions github-actions Bot added bug Something isn't working package: runtime Related to compio-runtime labels Jun 14, 2026
Runtime::run() calls executor.tick() without self.enter(), so
CURRENT_RUNTIME is not set. If a task polled or dropped during
tick() accesses the runtime (e.g. TimerFuture::poll or
TimerFuture::drop calling Runtime::with_current()), it panics
with "not in a compio runtime".

This affects any code that calls run() outside block_on(), such
as custom event loops or manual executor drain after block_on().

Wrap the tick() call in self.enter() so the thread-local is set,
matching what block_on() already does.
@paddor
paddor force-pushed the fix/runtime-run-tls branch from e765da8 to 1cc45d2 Compare June 14, 2026 20:30
@Berrysoft

Copy link
Copy Markdown
Member

This is intended. Runtime::run is a low level API, and we assume that the user knows when to call Runtime::enter.

@Berrysoft Berrysoft closed this Jun 14, 2026
@paddor

paddor commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Good to know. Thanks

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

Labels

bug Something isn't working package: runtime Related to compio-runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants