Repository navigation
fix(logging): make logging state constant-initialized - #8
Merged
Merged
Conversation
InitLogging() acquires a base::Lock stored in the namespace-scope global g_log_file, whose constructor sets up the underlying CRITICAL_SECTION on Windows. If sentry_init() (and therefore InitLogging()) runs from a static initializer that executes before this translation unit's dynamic initializers -- e.g. an initializer emitted into .CRT$XCL via #pragma init_seg(lib) or into .CRT$XCA* -- the CRITICAL_SECTION is still zero-filled and EnterCriticalSection faults with an access violation before main() is reached. Remove the dynamic initializer from g_log_file so it is safe to touch at any point after CRT startup: - Replace base::Lock with a small LogLock that is constant-initializable: SRWLOCK (SRWLOCK_INIT) on Windows and std::mutex (constexpr constructor) elsewhere. A zero/constant-initialized SRWLOCK is a valid, unlocked lock, so no constructor needs to have run. - Hold the log path in std::optional<base::FilePath> (constexpr default) so the struct no longer embeds a non-constant-initializable std::wstring. - Declare g_log_file constinit where the language provides it; the initialization is already constant under C++17. The lazy-open behavior, the silent close-on-exit handle, and the enabled flag are unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
JoshuaMoelans
approved these changes
Jul 31, 2026
jpnurmi
approved these changes
Aug 3, 2026
1 task
social4hyq
pushed a commit
to social4hyq/homebrew-core
that referenced
this pull request
Sep 20, 2026
sentry-native 0.16.2 Created-by: HarmonybrewBot Commit-by: HarmonybrewBot Merged-by: HarmonybrewBot Description: Created by `brew bump` --- Created with `brew bump-formula-pr`. - [ ] `resource` blocks have been checked for updates. <details> <summary>release notes</summary> <pre>**Features**: - Add `sentry_scope_remove_fingerprint` to remove a fingerprint set on a scope, matching the global `sentry_remove_fingerprint`. ([#1932](getsentry/sentry-native#1932)) - Add `sentry_options_set_before_send_feedback` to filter or enrich user feedback. Feedback does not go through `before_send`. ([#1923](getsentry/sentry-native#1923)) - Unix: Add `SENTRY_LINK_CURL` to control whether the curl transport links `libcurl` directly, loads it dynamically at runtime, or uses the default behavior. ([#1954](getsentry/sentry-native#1954)) **Fixes**: - Name `sentry-logs` and `sentry-metrics` telemetry batcher threads so they can be identified in debuggers, profilers, and crash reports. ([#1937](getsentry/sentry-native#1937)) - Linux: close descriptor `0` on failed module file mapping when that descriptor was returned by `open`, avoiding a file descriptor leak. ([#1924](getsentry/sentry-native#1924)) - `sentry_attachment_set_filename`, `sentry_attachment_set_type`, and `sentry_attachment_set_content_type` now flush the scope, so changes applied after `sentry_attach_file`/`sentry_attach_bytes` also apply to hard-crash events instead of only to normal events. ([#1934](getsentry/sentry-native#1934)) - Crashpad: fix a crash when calling `sentry_init` before C++ dynamic initializers have run. ([#1930](getsentry/sentry-native#1930), [mini_chromium#8](getsentry/mini_chromium#8)) - Reduce the size of native-generated minidumps on Windows ([#1929](https://github.com/getsentry/sentry-native/pull/1929))</pre> <p>View the full release notes at <a href="https://github.com/getsentry/sentry-native/releases/tag/0.16.2">https://github.com/getsentry/sentry-native/releases/tag/0.16.2</a>.</p> </details> <hr> See merge request: Harmonybrew/homebrew-core!16247
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On Windows,
sentry_init()crashes with an access violation when it runs from a C++ static initializer that executes before the compiler-generated dynamic initializers in.CRT$XCU.Report: getsentry/sentry-native#1930.
This regressed after the file-logging change (#6) added the lock; it worked before that.
Fix
Remove the dynamic initializer from
g_log_fileso its state is valid from image load, before any initializer runs