Skip to content

io: mandate stdio operations#7178

Open
maminrayej wants to merge 3 commits intotokio-rs:masterfrom
maminrayej:fix/use-spawn-mandatory-blocking
Open

io: mandate stdio operations#7178
maminrayej wants to merge 3 commits intotokio-rs:masterfrom
maminrayej:fix/use-spawn-mandatory-blocking

Conversation

@maminrayej
Copy link
Copy Markdown
Member

Previously stdio operations were not mandatory to run, so these operations could be shutdown even if they were scheduled before runtime shutdown. This PR replaces the use of spawn_blocking with spawn_mandatory_blocking in order to mandate the execution of stdio operations.

Resolves #7174.

@maminrayej maminrayej added A-tokio Area: The main tokio crate M-io Module: tokio/io labels Feb 25, 2025
Comment thread tokio/src/io/blocking.rs
enum State<T> {
Idle(Option<Buf>),
Busy(sys::Blocking<(io::Result<usize>, Buf, T)>),
Shutdown,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is there a new state?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

At first, I changed the Busy state to:

Busy(Option<sys::Blocking<(io::Result<usize>, Buf, T)>>)

since spawn_mandatory_blocking optionally returns a JoinHandle. But now Busy is representing two states:

  • Busy(Some(jh)): the task has been registered and will be picked up by one of the threads
  • Busy(None): the runtime is shutting down
    I think it makes sense to only use Busy for the first one and introduce the Shutdown state to represent the second one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess under the current implementation, the spawn_blocking call panics and then you end up in the Idle(None) state.

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

Labels

A-tokio Area: The main tokio crate M-io Module: tokio/io

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Occasional data loss with .write_all on io::stdout() without explicit .flush

2 participants