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

Stop log-forwarding thread on IO errors #133

Merged
merged 1 commit into from
Nov 20, 2023

Conversation

MarijnS95
Copy link
Member

Fixes #132

When read_line() starts returning Err the current if let Ok condition ignores those, likely causing the loop to spin indefinitely while this function keeps returning errors.

Note that we don't currently store the join handle for this thread anywhere, so won't see the error surface either (just like how the join handle for the main thread is never checked). Perhaps we should call log::error!() to make the user aware that their IO logging has mysteriously terminated.

@MarijnS95 MarijnS95 force-pushed the marijn/bail-log-thread-on-read_line-error branch from 9e600c2 to 530c58e Compare October 16, 2023 16:41
@MarijnS95 MarijnS95 changed the title Bail on errors in log-forwarding thread Stop log-forwarding thread on IO errors Oct 16, 2023
@MarijnS95 MarijnS95 force-pushed the marijn/bail-log-thread-on-read_line-error branch from 530c58e to 4722c7c Compare October 17, 2023 16:05
@MarijnS95 MarijnS95 requested a review from rib October 24, 2023 18:35
@MarijnS95
Copy link
Member Author

@rib we probably want to have this in so that I can test rustix on top.

@MarijnS95 MarijnS95 mentioned this pull request Nov 18, 2023
Copy link
Collaborator

@rib rib left a comment

Choose a reason for hiding this comment

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

Yeah I suppose it's a bit more faff, but it could be nice if we'd log some kind of clue if you hit a spurious error here. If you want to leave that for a separate follow up that's ok though.

Not required but it could also be nice to share a utility for spawning this stdio thread since the code is identical between the two backends.

@MarijnS95 MarijnS95 force-pushed the marijn/bail-log-thread-on-read_line-error branch from 4722c7c to a9985cf Compare November 20, 2023 13:11
@MarijnS95
Copy link
Member Author

but it could be nice if we'd log some kind of clue if you hit a spurious error here

Done.

If you want to leave that for a separate follow up that's ok though.

Let's leave stopping+joining the thread for a followup, as we'd have to close stdin/stdout - hoping they haven't been dup2()'d elsewhere - to trigger a len == 0read and exit the thread before calling.join()`.

Not required but it could also be nice to share a utility for spawning this stdio thread since the code is identical between the two backends.

Done, good idea. The util module already exists for exactly this purpose anyway.

When `read_line()` starts returning `Err` the current `if let Ok`
condition ignores those, likely causing the `loop` to spin indefinitely
while this function keeps returning errors.

Note that we don't currently store the join handle for this thread
anywhere, so won't see the error surface either (just like how the join
handle for the main thread is never checked).  Perhaps we should call
`log::error!()` to make the user aware that their IO logging has
mysteriously terminated.
@MarijnS95 MarijnS95 force-pushed the marijn/bail-log-thread-on-read_line-error branch from a9985cf to af34189 Compare November 20, 2023 13:15
Copy link
Collaborator

@rib rib left a comment

Choose a reason for hiding this comment

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

Even though this was originally proposed in #145 I guess it makes sense to just name this thread here while creating a shared utility for spawning the stdio thread.

This looks good to me, thanks.

@rib rib merged commit bfd8bfd into main Nov 20, 2023
3 checks passed
@rib rib deleted the marijn/bail-log-thread-on-read_line-error branch November 20, 2023 13:24
@MarijnS95
Copy link
Member Author

Yeah I hope @fornwall doesn't mind some preliminary conflict resolution... Though I can revert it.

@fornwall
Copy link
Collaborator

Yeah I hope @fornwall doesn't mind some preliminary conflict resolution... Though I can revert it.

Absolutely no problem, I'll fix!

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.

Fix the error handling for the stdin/err IO thread and exit loop on io::Error
3 participants