-
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
[crashtracker] Enable client to configure which signals to trap #856
base: main
Are you sure you want to change the base?
Conversation
SigHandler::Handler(f) => f(signum), | ||
SigHandler::SigAction(f) => f(signum, sig_info, ucontext), | ||
}; | ||
eprintln!("Unexpected signal number {signum}, can't chain the handlers"); |
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.
What should we do here? abort?
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.
I guess this could happen if the user code changes the sigaction while we're in the middle of handling a signal? I'm not sure how it might arise.
unsafe { create_alt_stack()? }; | ||
} | ||
let mut old_handlers = HashMap::new(); | ||
// TODO: if this fails, we end in a situation where handlers have been registered with no chain |
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.
What to do here?
let boxed_ptr = Box::into_raw(Box::new(old_handlers)); | ||
|
||
let res = OLD_HANDLERS.compare_exchange(ptr::null_mut(), boxed_ptr, SeqCst, SeqCst); | ||
anyhow::ensure!( |
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.
This leaks the old_handlers, if we care?
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.
I don't think so--small one-time leak, right?
@@ -674,9 +665,11 @@ pub fn restore_old_handlers(inside_signal_handler: bool) -> anyhow::Result<()> { | |||
anyhow::ensure!(!prev.is_null(), "No crashtracking previous signal handlers"); | |||
// Safety: The only nonnull pointer stored here comes from Box::into_raw() | |||
let prev = unsafe { Box::from_raw(prev) }; |
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.
We could flip this around, and only rehydrate into a box when we are ready to drop it
BenchmarksComparisonBenchmark execution time: 2025-02-12 17:57:05 Comparing candidate commit a6154dd in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 52 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
Group 13
BaselineOmitted due to size. |
8050f45
to
90442a0
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #856 +/- ##
==========================================
- Coverage 71.90% 71.67% -0.24%
==========================================
Files 324 324
Lines 48077 48226 +149
==========================================
- Hits 34572 34568 -4
- Misses 13505 13658 +153
|
One thing I strongly recommend is: let's put in some defaults! In past features "leaving it up to implementer" often meant unintended inconsistency as things get picked semi-randomly; I think in general it's nice to have a pattern of "if you don't want to choose, we pick a reasonable default, don't worry about it". |
https://github.com/DataDog/libdatadog/pull/856/files#diff-fded76796d1b1945fd14d3cdb6230e4692e94608fc4887d26e2530a004df451aR59 |
Ahaha my bad for scrolling too fast through the PR, and amazing work in getting this in :D :D :D |
SigHandler::Handler(f) => f(signum), | ||
SigHandler::SigAction(f) => f(signum, sig_info, ucontext), | ||
}; | ||
eprintln!("Unexpected signal number {signum}, can't chain the handlers"); |
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.
I guess this could happen if the user code changes the sigaction while we're in the middle of handling a signal? I'm not sure how it might arise.
let boxed_ptr = Box::into_raw(Box::new(old_handlers)); | ||
|
||
let res = OLD_HANDLERS.compare_exchange(ptr::null_mut(), boxed_ptr, SeqCst, SeqCst); | ||
anyhow::ensure!( |
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.
I don't think so--small one-time leak, right?
What does this PR do?
Instead of hardcoding the signals to trap, allow the client to specify them
Motivation
We wanted to catch sigabort and sigill in addition to sigsegv and sigbus, and I figured lets just make it generic.
Additional Notes
Anything else we should know when reviewing?
How to test the change?