-
Notifications
You must be signed in to change notification settings - Fork 167
Profiling: fix UB and simplify SystemSettings #3578
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
Conversation
| git_repository_url: None, | ||
| tags: vec![], | ||
| system_settings: ptr::NonNull::from(INITIAL_SYSTEM_SETTINGS.deref()), | ||
| system_settings: SystemSettings::get(), |
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.
Here's an example of a potential behavior divergence. Before, this would have used INITIAL_SYSTEM_SETTINGS which would have done AgentEndpoint::default(), but now, it will have the value SystemSettings uses, which could just be the socket depending on when exactly it was called. More precisely, AgentEndpoint::default() checks that the apm.socket exists before using it, and if it doesn't exist, it falls back to the URI.
Now, this shouldn't really matter in any scenarios, because we really should be changing these to real values ASAP. It's something to specifically scrutinize in the PR.
| // Initialize the lazy lock holding the env var for new origin detection. | ||
| _ = std::sync::LazyLock::force(&libdd_common::entity_id::DD_EXTERNAL_ENV); |
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 is unrelated to this PR, but it's a safer place for it. Maybe I should make it its own PR but it's 10:35pm for me right now when I noticed this.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3578 +/- ##
==========================================
- Coverage 62.02% 61.92% -0.11%
==========================================
Files 140 140
Lines 13309 13309
Branches 1762 1762
==========================================
- Hits 8255 8241 -14
- Misses 4265 4278 +13
- Partials 789 790 +1 see 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Benchmarks [ profiler ]Benchmark execution time: 2026-01-15 20:27:30 Comparing candidate commit 4352c47 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 28 metrics, 8 unstable metrics. |
Benchmarks [ tracer ]Benchmark execution time: 2026-01-15 06:34:50 Comparing candidate commit 8afb20c in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 192 metrics, 1 unstable metrics. scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache
|
8afb20c to
32db8b9
Compare
|
The key reason the stale URI won't be an issue is because |
| let addr = unsafe { (*ptr::addr_of_mut!(SYSTEM_SETTINGS)).assume_init_mut() }; | ||
| ptr::NonNull::from(addr) | ||
| /// Returns the "current" system settings, which are always memory-safe | ||
| /// but may point to "initial" values rather than the configured ones, |
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.
should there be an "is_initial" field on the settings for debugging purposes?
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've pushed a commit with state tracking, I'll play a little bit with it but don't have time for a lot of experimentation right now.
This also serves to document some AtomicPtr operations and orderings.
a7b55fc to
b6efbb8
Compare
b6efbb8 to
4352c47
Compare
| #[derive(Copy, Clone, Debug, Default)] | ||
| pub enum SystemSettingsState { | ||
| /// Indicates the system settings are not aware of the configuration at | ||
| /// the moment. | ||
| #[default] | ||
| ConfigUnaware, | ||
|
|
||
| /// Indicates the system settings _are_ aware of configuration at the | ||
| /// moment. | ||
| ConfigAware, | ||
|
|
||
| /// Expressly disabled, such as a child process post-fork (forks are not | ||
| /// currently profiled, except certain forks made by SAPIs). | ||
| Disabled, | ||
| } | ||
|
|
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 like that 👍
Description
Currently we're using
MaybeUninitand doing various memory operations onSYSTEM_SETTINGS. With a tweak made in #3577, we can simplify this.Additionally, this fixes likely undefined behavior on ZTS and possibly even NTS builds as well. There was a mutable reference taken to the
SystemSettingsinrinit. Note that we did not actually mutate it, so in practice we were likely fine, but this would have been instant undefined behavior simply to materialize the mutable reference if any other references existed, which in ZTS would have been quite likely (other workers could also be inrinit).Note that there shouldn't be any meaningful changes with regards to the change in the URI default, but there is one thing in particular we should watch out for: the default uri may have changed if we have some bad logic somewhere. I'll call it out with a CR comment.
Reviewer checklist