Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: mandate stdio operations #7178

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

maminrayej
Copy link
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
@@ -30,6 +30,7 @@ pub(crate) const DEFAULT_MAX_BUF_SIZE: usize = 2 * 1024 * 1024;
enum State<T> {
Idle(Option<Buf>),
Busy(sys::Blocking<(io::Result<usize>, Buf, T)>),
Shutdown,
Copy link
Contributor

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
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
Contributor

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