Skip to content

Survive static destruction order failure in AWSLogging accessors#3874

Open
makxenov wants to merge 1 commit into
aws:mainfrom
makxenov:fix-awslogging-static-destruction-order
Open

Survive static destruction order failure in AWSLogging accessors#3874
makxenov wants to merge 1 commit into
aws:mainfrom
makxenov:fix-awslogging-static-destruction-order

Conversation

@makxenov

Copy link
Copy Markdown

Description of changes:
The logger is held in two namespace-scope shared_ptr statics. AWS clients owned by other translation units can be destroyed after these statics (the order of static destruction across translation units is unspecified) and may still call GetLogSystem()/Push/PopLogger while unwinding at process exit. Once the shared_ptrs have been destroyed, those calls touch freed objects.

Move the two shared_ptrs into a LoggingSet struct guarded by a trivially destructible bool flag, LoggingSetAlive, which stays readable until the very end of the process. ~LoggingSet clears the flag; afterwards the accessors behave as if no logger is installed instead of reading the destroyed members.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain: the order on destruction is unspecified)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

The logger is held in two namespace-scope shared_ptr statics. AWS clients
owned by other translation units can be destroyed after these statics (the
order of static destruction across translation units is unspecified) and may
still call GetLogSystem()/Push/PopLogger while unwinding at process exit. Once
the shared_ptrs have been destroyed, those calls touch freed objects.

Move the two shared_ptrs into a LoggingSet struct guarded by a trivially
destructible bool flag, LoggingSetAlive, which stays readable until the very
end of the process. ~LoggingSet clears the flag; afterwards the accessors
behave as if no logger is installed instead of reading the destroyed members.
@makxenov makxenov changed the title Survive static destruction order in AWSLogging accessors Survive static destruction order failure in AWSLogging accessors Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant