Skip to content
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

auth: Initialization ordering of global objects is unspecified #13681

Open
rgacogne opened this issue Jan 9, 2024 · 1 comment
Open

auth: Initialization ordering of global objects is unspecified #13681

rgacogne opened this issue Jan 9, 2024 · 1 comment

Comments

@rgacogne
Copy link
Member

rgacogne commented Jan 9, 2024

  • Program: Authoritative
  • Issue type: Bug report

Short description

As reported by Coverity in several defects, we have a problem with the initialization order of global objects. For example, as reported in CID 1524949: Initialization or destruction ordering is unspecified:

  • We have a global gSQLite3Loader defined in gsqlite3backend.cc
  • the constructor calls Logger::operator<<()
  • which calls S.ringAccount()

This means we need the global StatBag object S to exist before the gSQLite3Loader object is created, but we have no guarantee this will be the case.

I attempted to solve this in #13629 by turning StagBag into a singleton, thus ensuring it is created before being used. @fredmorcos went about it in a different way in #13613, by passing the StagBag object as a parameter to the functions that need it. While the second approach is cleaner, it might be difficult to do it at scale given how widespread the use of S is.

@fredmorcos
Copy link
Contributor

The approach I took was not meant to be done entirely in one go. So it's alright if we fix things up bit by bit over time, where each of us could do a small part in this.

Ideally we completely get rid of globals, mutable or not, because they cause issues with other things like linking when we split up our codebase into libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants