-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
avikivity
merged 1 commit into
scylladb:master
from
michael-redpanda:do-not-assert-on-waitpid
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
std::chrono::milliseconds& wait_timeout) { | ||
return repeat_until_value([this, | ||
pid, | ||
&wstatus, | ||
&wait_timeout] { | ||
return _thread_pool->submit<syscall_result<pid_t>>([pid, &wstatus] { | ||
return wrap_syscall<pid_t>(::waitpid(pid, &wstatus, WNOHANG)); | ||
}).then([&wstatus, &wait_timeout](syscall_result<pid_t> ret) mutable { | ||
if (ret.result == 0) { | ||
wait_timeout = next_waitpid_timeout(wait_timeout); | ||
return ::seastar::sleep(wait_timeout).then([] { | ||
return make_ready_future<std::optional<int>>(); | ||
}); | ||
} else if (ret.result > 0) { | ||
return make_ready_future<std::optional<int>>(wstatus); | ||
} else { | ||
ret.throw_if_error(); | ||
return make_ready_future<std::optional<int>>(-1); | ||
} | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
future<int> reactor::waitpid(pid_t pid) { | ||
return _thread_pool->submit<syscall_result<int>>([pid] { | ||
return wrap_syscall<int>(syscall(__NR_pidfd_open, pid, O_NONBLOCK)); | ||
|
@@ -2083,39 +2109,11 @@ future<int> reactor::waitpid(pid_t pid) { | |
// pidfd_open() was introduced in linux 5.3, so the pidfd.error could be ENOSYS on | ||
// older kernels. But it could be other error like EMFILE or ENFILE. anyway, we | ||
// should always waitpid(). | ||
return do_with(int{}, std::chrono::milliseconds(0), [pid, this](int& wstatus, | ||
std::chrono::milliseconds& wait_timeout) { | ||
return repeat_until_value([this, | ||
pid, | ||
&wstatus, | ||
&wait_timeout] { | ||
return _thread_pool->submit<syscall_result<pid_t>>([pid, &wstatus] { | ||
return wrap_syscall<pid_t>(::waitpid(pid, &wstatus, WNOHANG)); | ||
}).then([&wstatus, &wait_timeout] (syscall_result<pid_t> ret) mutable { | ||
if (ret.result == 0) { | ||
wait_timeout = next_waitpid_timeout(wait_timeout); | ||
return ::seastar::sleep(wait_timeout).then([] { | ||
return make_ready_future<std::optional<int>>(); | ||
}); | ||
} else if (ret.result > 0) { | ||
return make_ready_future<std::optional<int>>(wstatus); | ||
} else { | ||
ret.throw_if_error(); | ||
return make_ready_future<std::optional<int>>(-1); | ||
} | ||
}); | ||
}); | ||
}); | ||
return do_waitpid(pid); | ||
} else { | ||
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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
}); | ||
}).then([&wstatus] (syscall_result<pid_t> ret) { | ||
ret.throw_if_error(); | ||
assert(ret.result > 0); | ||
return make_ready_future<int>(wstatus); | ||
return do_with(pollable_fd(file_desc::from_fd(pidfd.result)), [pid, this](auto& pidfd) { | ||
return pidfd.readable().then([pid, this] { | ||
return do_waitpid(pid); | ||
}); | ||
}); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2532