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

reactor: Always retry waitpid #2531

Merged

Conversation

michael-redpanda
Copy link
Contributor

A possible issue with how Docker Desktop v4.34+ (particulary on macOS) handles pidfd functionality causes an assertion failure in Seastar's reactor::waitpid method.

The issue:

  • Seastar creates a pidfd using pidfd_open
  • It polls this file descriptor until it becomes readable
  • When readable, call waitpid with WNOHANG. According to pidfd_open, the file descriptor becomes readable when the process terminates
  • Seastar expects waitpid to either return a positive integer representing the child process that has ended or a negative value to indicate an error. However if waitpid returns 0, then Seastar asserts, crashing the using application.

This change adds reactor::do_waitpid which loops on calling waitpid until it returns a non-zero value. This method is called both when a pidfd is in use and when it isn't. The assertion is also removed.

A possible issue with how Docker Desktop v4.34+ (particulary on macOS)
handles `pidfd` functionality causes an assertion failure in Seastar's
`reactor::waitpid` method.

The issue:

- Seastar creates a `pidfd` using `pidfd_open`
- It polls this file descriptor until it becomes readable
- When readable, call `waitpid` with `WNOHANG`.  According to
  [pidfd_open](https://man7.org/linux/man-pages/man2/pidfd_open.2.html),
  the file descriptor becomes readable when the process terminates
- Seastar expects `waitpid` to either return a positive integer
  representing the child process that has ended or a negative value to
  indicate an error.  However if `waitpid` returns `0`, then Seastar
  asserts, crashing the using application.

This change adds `reactor::do_waitpid` which loops on calling `waitpid`
until it returns a non-zero value.  This method is called both when a
`pidfd` is in use and when it isn't.  The assertion is also removed.

Signed-off-by: Michael Boquard <[email protected]>
@@ -2075,6 +2075,32 @@ static auto next_waitpid_timeout(std::chrono::milliseconds this_timeout) {

#endif

future<int> reactor::do_waitpid(pid_t pid) {
return do_with(int{}, std::chrono::milliseconds(0), [pid, this](int& wstatus,
Copy link
Member

Choose a reason for hiding this comment

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

Please use coroutines in new code.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you're just moving old code around. ok.

Copy link
Member

Choose a reason for hiding this comment

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

return do_with(pollable_fd(file_desc::from_fd(pidfd.result)), int{}, [pid, this](auto& pidfd, int& wstatus) {
return pidfd.readable().then([pid, &wstatus, this] {
return _thread_pool->submit<syscall_result<pid_t>>([pid, &wstatus] {
return wrap_syscall<pid_t>(::waitpid(pid, &wstatus, WNOHANG));
Copy link
Member

Choose a reason for hiding this comment

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

Presumably, using _thread_pool here (and above) is wrong, since WNOHANG means the kernel won't block.

@avikivity avikivity merged commit fb6c969 into scylladb:master Nov 9, 2024
15 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.

3 participants