-
Notifications
You must be signed in to change notification settings - Fork 10
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
[crashtracking] improve poll waiting logic #754
Conversation
BenchmarksComparisonBenchmark execution time: 2024-11-25 20:51:20 Comparing candidate commit 8074728 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 51 metrics, 2 unstable metrics. CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
BaselineOmitted due to size. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #754 +/- ##
==========================================
- Coverage 70.49% 70.47% -0.02%
==========================================
Files 297 297
Lines 43401 43411 +10
==========================================
Hits 30595 30595
- Misses 12806 12816 +10
|
_ => Err(anyhow::anyhow!("poll returned unexpected result")), | ||
}, | ||
let mut poll_fds = [pollfd { | ||
fd: target_fd, |
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.
+1 - BorrowedFd prefferably should be use in conjuction with OwnedFd. borrow_raw - without any guarantees of FD lifetime is problematic.
Probably the safest option would be to dup the fd - and own it within the context of this function.
Otherwise the code looks like correct but "C'ish" rust :)
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.
#758 to track
let reaping_allowed_ms = std::cmp::min( | ||
timeout_ms.saturating_sub(start_time.elapsed().as_millis() as u32), | ||
DD_CRASHTRACK_MINIMUM_REAP_TIME_MS, | ||
); | ||
|
||
let _ = reap_child_non_blocking(receiver_pid_as_pid, reaping_allowed_ms); |
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.
return Err(anyhow::anyhow!("Timeout waiting for child process to exit"));
In sidecar - we send kill and term. When the timeout ends.
And it looks that - we're not doing that here either way - so a non 0 timeout will only reduce the incidence of zombies. Not prevent them.
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.
Don't we do that just above? https://github.com/DataDog/libdatadog/blob/main/crashtracker/src/collector/crash_handler.rs#L483
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.
Approved - because Its an improvement over previous code. But it looks like some issues with zombies can still show up from time to time.
_ => Err(anyhow::anyhow!("poll returned unexpected result")), | ||
}, | ||
let mut poll_fds = [pollfd { | ||
fd: target_fd, |
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.
#758 to track
revents: 0, | ||
}]; | ||
|
||
match unsafe { poll(poll_fds.as_mut_ptr(), 1, timeout_ms) } { |
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.
style: this should be .len
not constant 1
revents if revents.contains(PollFlags::POLLHUP) => Ok(true), | ||
_ => Err(anyhow::anyhow!("poll returned unexpected result")), | ||
}, | ||
let mut poll_fds = [pollfd { |
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.
comment to explain the meaning of the boolean result
let reaping_allowed_ms = std::cmp::min( | ||
timeout_ms.saturating_sub(start_time.elapsed().as_millis() as u32), | ||
DD_CRASHTRACK_MINIMUM_REAP_TIME_MS, | ||
); | ||
|
||
let _ = reap_child_non_blocking(receiver_pid_as_pid, reaping_allowed_ms); |
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.
Don't we do that just above? https://github.com/DataDog/libdatadog/blob/main/crashtracker/src/collector/crash_handler.rs#L483
What does this PR do?
The original implementation accidentally had a mutable array with immutable objects, causing the interface to always throw errors. Since this part of the code is in the critical path for handling zombie processes, this condition had an adverse side-effect on customer infrastructure.
This code also used a
BorrowedFd
, which is supposed to track anOwnedFd
. This was problematic in some conditions, since the underlying implementation would useprctl()
to check file descriptor liveness and panic in some edge-cases. The code has been ported to libc, using exclusivelyRawFd
, in order to prevent this condition.Finally, this patch grants some additional time to the act of reaping a PID. When a receiver process exceeds its timeout budget, it's sent a
SIGKILL
. However, the old behavior was toSIGKILL
, the immediatelywaitpid( pid, ..., WNOHANG)
. On a saturated system (i.e., precisely the kind of system where a timeout might be necessary!), it may take some time for the receiver PID to respond to theSIGKILL
.In general, there's no way to provided a bounded guarantee for the duration of this reap operation, so an arbitrary number of scheduler slices is chosen as the maximum reaping wait duration.
Motivation
Fix zombies