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

fix: Use a different std::thread::Thread for Stdin IO #69

Merged
merged 2 commits into from
Dec 11, 2024

Conversation

vrongmeal
Copy link
Member

See: https://docs.rs/tokio/latest/tokio/io/struct.Stdin.html

This handle is best used for non-interactive uses, such as when a
file is piped into the application. For technical reasons, stdin is
implemented by using an ordinary blocking read on a separate thread,
and it is impossible to cancel that read. This can make shutdown of
the runtime hang until the user presses enter.

For interactive uses, it is recommended to spawn a thread dedicated to
user input and use blocking IO directly in that thread.

Resolves: #61

See: https://docs.rs/tokio/latest/tokio/io/struct.Stdin.html

> This handle is best used for non-interactive uses, such as when a
> file is piped into the application. For technical reasons, stdin is
> implemented by using an ordinary blocking read on a separate thread,
> and it is impossible to cancel that read. This can make shutdown of
> the runtime hang until the user presses enter.
>
> For interactive uses, it is recommended to spawn a thread dedicated to
> user input and use blocking IO directly in that thread.

Resolves: #61

Signed-off-by: Vaibhav Rabber <[email protected]>
@vrongmeal vrongmeal requested a review from a team as a code owner December 11, 2024 17:06
src/main.rs Outdated Show resolved Hide resolved
Copy link
Member

@infiniteregrets infiniteregrets left a comment

Choose a reason for hiding this comment

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

I made a change to use std::process::exit as normal return Ok(()) wouldnt work.. maybe that can changed back to normal now?

@vrongmeal
Copy link
Member Author

I made a change to use std::process::exit as normal return Ok(()) wouldnt work.. maybe that can changed back to normal now?

Oh yeah, should be. Which change is this BTW? I'll revert it.

@infiniteregrets
Copy link
Member

Oh yeah, should be. Which change is this BTW? I'll revert it.

can't find it, but can you just try breaking from the loop and do return Ok(()). try it with the starwars example, and see if the process exits on ctrl+C

Signed-off-by: Vaibhav Rabber <[email protected]>
Copy link
Member

@infiniteregrets infiniteregrets left a comment

Choose a reason for hiding this comment

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

thanks for finding and fixing this!

@vrongmeal vrongmeal merged commit 2b47c77 into main Dec 11, 2024
2 checks passed
@vrongmeal vrongmeal deleted the vrongmeal/append-hang branch December 11, 2024 17:36
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.

append to non-existent stream "hangs"
2 participants