fix endless loop on crash after init during +load #338
+30
−24
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.
Things to consider before you submit the PR:
CHANGELOG.md
been updated?Description
This PR fixes an issue in the PLCrashReporter, where a static initialization of units (in the +load method), could lead to an endless loop when trying to handle a crash.
This happens because the crash callback handlers are set even though the static shared_handler_context is not initialized yet. Once the shared_handler_context gets initialized, the list of callbacks initialized as empty. This leads to an endless loop, as no callback to handle a crash is available.
The underlying issue is connected to the (Static Initialization Order Fiasco)[https://en.cppreference.com/w/cpp/language/siof], due to initialization of static objects from different translation units when one depends on the other being initialized already.
Solution
We need to force the static struct (shared_handler_context) to be initialized on first access. This PR achieves this by adapting the shared_handler_context to be used as a function and adapts its usage throughout the PLCrashSignalHandler. Using this approach, we can centralize the initialization and enforce a proper order, resolving the underlaying issue.
Related PRs or issues
#325
Misc
All tests are running through, except
testStackWalkerRegression
, but this one also fails for me locally on master.Not sure how to properly unit test this since it's pretty hard to reproduce and needs another app to load it during it's load.