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

linux: fix a hang if there are no reads from the tty #1623

Merged
merged 6 commits into from
Dec 16, 2024

Conversation

giuseppe
Copy link
Member

avoid a "crun exec" hang when the the other end of the terminal stopped reading.

That happened because copy_fd_to_fd tried to write everything that it has received from the source fd, so it would hang the current process. Prevent that using non blocking file descriptors and using epoll to detect when the file descriptor is available for write.

Fixes: https://issues.redhat.com/browse/OCPBUGS-45632

@giuseppe
Copy link
Member Author

marked as a draft, as I need to test it more

@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch 6 times, most recently from 4555a83 to a8a67b4 Compare December 13, 2024 14:59
@giuseppe giuseppe marked this pull request as ready for review December 13, 2024 14:59
@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from a8a67b4 to 61c2d7d Compare December 13, 2024 15:21
@haircommander
Copy link
Contributor

this PR fixes the problem as expected 🎉

@rhatdan
Copy link
Member

rhatdan commented Dec 13, 2024

/approve
/lgtm

@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from 61c2d7d to c1c2271 Compare December 13, 2024 21:51
@giuseppe giuseppe marked this pull request as draft December 14, 2024 20:58
@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from c1c2271 to 50b60e2 Compare December 14, 2024 21:47
src/libcrun/utils.c Fixed Show fixed Hide fixed
@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from 50b60e2 to 67d862e Compare December 14, 2024 22:01
@giuseppe giuseppe marked this pull request as ready for review December 14, 2024 22:06
int ret, container_exit_code = 0, last_process;
cleanup_close int terminal_fd_from = -1;
cleanup_close int terminal_fd_to = -1;
const size_t max_events = 10;
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to make this a definition with an added comment about what it's for?

Copy link
Member Author

Choose a reason for hiding this comment

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

not sure, I can add a comment if you feel we need it, but this is an arbitrary limit defined only to avoid using the same constant multiple times.

Copy link
Member

Choose a reason for hiding this comment

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

No worries. This is fine, too. A #define is just a habit.

commit 1832c17 introduced the change.

Signed-off-by: Giuseppe Scrivano <[email protected]>
Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from 67d862e to c687e11 Compare December 16, 2024 10:01
Copy link

Ephemeral COPR build failed. @containers/packit-build please check.

@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from c687e11 to 66be626 Compare December 16, 2024 10:15
avoid a "crun exec" hang when the the other end of the terminal
stopped reading.

That happened because `copy_fd_to_fd` tried to write everything that
it has received from the source fd, so it would hang the current
process.  Prevent that using non blocking file descriptors and using
epoll to detect when the file descriptor is available for write.

Fixes: https://issues.redhat.com/browse/OCPBUGS-45632

Signed-off-by: Giuseppe Scrivano <[email protected]>
@giuseppe giuseppe force-pushed the fix-hang-on-unresponsive-tty branch from 66be626 to 8b972be Compare December 16, 2024 12:58
@giuseppe
Copy link
Member Author

@saschagrunert @haircommander PTAL. It is ready to merge (assuming a happy CI)

Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe giuseppe merged commit 3dbc7e7 into containers:main Dec 16, 2024
51 of 53 checks passed
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.

5 participants