8000 Introduce a timeout to prevent `rb_thread_fd_select` from hanging with write(2) failure by shioimm · Pull Request #12457 · ruby/ruby · GitHub
[go: up one dir, main page]

Skip to content

Introduce a timeout to prevent rb_thread_fd_select from hanging with write(2) failure #12457

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 8000 “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

Merged
merged 1 commit into from
Dec 24, 2024

Conversation

shioimm
Copy link
Contributor
@shioimm shioimm commented Dec 24, 2024

Rarely, there are cases where a write(2) call from a child thread to notify the main thread of the completion of name resolution fails. If this happens while the main thread is waiting in rb_thread_fd_select, rb_thread_fd_select may not notice that the name resolution has completed and end up hanging.

This issue becomes a problem when there are no sockets currently being connected, no addresses ready for immediate connection attempts, and name resolution has already completed for one address family while the main thread is waiting for the name resolution of the other address family. (If name resolution is not completed for either address family, the chances of write(2) failing in both child threads are likely low.)

To avoid this issue, a timeout is introduced to rb_thread_fd_select under the above conditions. This way, even if the issue occurs,
the completion of name resolution should still be detected in the subsequent if (!resolution_store.is_all_finished) ... block.

…h write(2) failure

Rarely, there are cases where a write(2) call from a child thread
to notify the main thread of the completion of name resolution fails.
If this happens while the main thread is waiting in `rb_thread_fd_select`,
rb_thread_fd_select may not notice that the name resolution has completed and end up hanging.

This issue becomes a problem when there are no sockets currently being connected,
no addresses ready for immediate connection attempts,
and name resolution has already completed for one address family
while the main thread is waiting for the name resolution of the other address family.
(If name resolution is not completed for either address family,
the chances of write(2) failing in both child threads are likely low.)

To avoid this issue, a timeout is introduced to rb_thread_fd_select under the above conditions.
This way, even if the issue occurs,
the completion of name resolution should still be detected
in the subsequent `if (!resolution_store.is_all_finished) ...` block.
@shioimm shioimm force-pushed the timeout-for-failing-write branch from 27bd6d5 to d401538 Compare December 24, 2024 17:25
@shioimm shioimm marked this pull request as ready for review December 24, 2024 18:04
@shioimm shioimm merged commit 3be1baa into ruby:master Dec 24, 2024
77 checks passed
@Pricer187

This comment was marked as spam.

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.

2 participants
0