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

Delaying LOG4CXX initialization until first actual use (DM-6989) #12

Merged
merged 2 commits into from Jul 22, 2016

Conversation

andy-slac
Copy link
Contributor

Previously LOG4CXX was initialized at DSO loading time (at globals
initialization time) which caused issues with global destructors
ordering. This patch delays initialization until first actual use of
logging methods which partially resolves the issue (there are still
possible use cases when the problems can re-appear).

Also some cleanup to macros for efficiency and simplicity after recent
changes to Log class.

Re-applied previous commit from DM-6521 - "Replace defaultLogger by a static method getDefaultLogger()"

Hsin-Fang Chiang and others added 2 commits July 21, 2016 18:06
Previously LOG4CXX was initializaed at DSO loading time (at globals
initialization time) which caused issues with global destructions
ordering. This patch delays initilization until first actual use of
logging methods which partially resolves the issue (there are still
possible use cases when the problems can re-appear).

Also some cleanup to macros for efficiency and simplicity after recent
changes to Log class.
@andy-slac andy-slac merged commit 64b8957 into master Jul 22, 2016
@RobertLuptonTheGood
Copy link
Member

I'm guessing that you're using a singleton?

It'd be good to elaborate on:
bq. there are still possible use cases when the problems can re-appear
(does this refer to multithreading?)

@andy-slac
Copy link
Contributor Author

andy-slac commented Jul 24, 2016

@RobertLuptonTheGood, indeed there is a singleton which is used as a default logger instance. That is not a problem by itself though, because there are globals in both LOG4CXX and activemq which are actual problem.

JIRA ticket (DM-6989) has an example of a use case when things may still break even after this fix. The problem is with a global root logger in LOG4CXX which keeps appender instantiated by ctrl_events which uses activemq (with its globals). Normally ctrl_events and activemq should be loaded before root logger is instantiated and when globals are destroyed the order is correct in a sense that root logger and its appenders are destroyed before activemq globals. But it is possible to break this order if one manages to instantiate root logger first and then load ctrl_events and activemq. Simplest example is like this:

import lsst.log as log
log.debug("lsst.log is imported")    # this will initialize log4cxx and create root logger
import lsst.ctrl.events              # this will instantiate activemq globals
# instantiate ctrl_events log appender via re-configuring log4cxx

With this use case the order of destruction is reversed, activemq globals will be destroyed first, then root logger is destroyed which calls appender destructor which tries to access activemq globals. The fix for this problem should be possible in ctrl_events.

@ktlim ktlim deleted the tickets/DM-6989 branch August 25, 2018 05:18
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.

None yet

2 participants