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
Buffer log messages and explicitly open logs #6149
Conversation
Concept ACK; I like making opening the debug log explicit. This will correctly handle any sequence of Shutdown() being called after AppInit2 errored out somewhere along the way? (just asking - previous changes in this sequence have tended to cause unexpected problems there) |
945ad84
to
784804a
Compare
It will now. I wasn't able to get it to crash in my testing, but I believe that it was possible if the list/buffer were left static. I believe the issue you're bringing up is #1832 where the mutex that protects the log was being destroyed before the log print functions were being called resulting in a crash on shutdown. The fix for that was to explicitly initialize the mutex and put it on the heap. This generally results in a leak of the mutex and the output fd even on clean shutdown, but that's just merely ugly and benign. (and to be clear, the way things are today) I now do the same with this buffer which will ensure that it is safe, but also leaked at exit along with the mutex and fd. I looked into cleaning up the shutdown stuff and explicitly destroying the mutex, closing the fd and deleting this buffer, but that's more involved (things are slightly different under QT and bitcoind) and it seems like different, more complex and more difficult to test PR that should probably stand alone. |
784804a
to
cd5ef83
Compare
*/ | ||
static FILE* fileout = NULL; | ||
static boost::mutex* mutexDebugLog = NULL; | ||
static list<string> *vMsgsBeforeOpenLog; | ||
|
||
int LogWriteStr(const std::string &str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function can be static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I'd suggest to rename it to FileWriteStr
, and pass in the file
argument explicitly. This makes for a clearer utility function.
Needs nits addressed, should otherwise be ready for merging. |
cd5ef83
to
a1b25a3
Compare
Prevents stomping on debug logs in datadirs that are locked by other instances and lost parameter interaction messages that can get wiped by ShrinkDebugFile(). The log is now opened explicitly and all emitted messages are buffered until this open occurs. The version message and log cut have also been moved to the earliest possible sensible location.
a1b25a3
to
27d7605
Compare
Nits addressed and rebased. Waiting for Travis... (which appears to be attempting to build the whole depends tree?) |
lightly tested ACK |
Tested ACK |
27d7605 Buffer log messages and explicitly open logs (Adam Weiss)
Bitcoin 0.12 misc PRs 1 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6198 - bitcoin/bitcoin#6206 - bitcoin/bitcoin#6152 - bitcoin/bitcoin#5927 - bitcoin/bitcoin#6213 - bitcoin/bitcoin#5975 - bitcoin/bitcoin#6061 - bitcoin/bitcoin#6283 (partial, remainder was pulled in #929) - bitcoin/bitcoin#6272 - bitcoin/bitcoin#6316 - bitcoin/bitcoin#6299 (partial, remainder in #2100) - bitcoin/bitcoin#6133 - bitcoin/bitcoin#6361 - bitcoin/bitcoin#6387 - bitcoin/bitcoin#6401 - bitcoin/bitcoin#6370 - bitcoin/bitcoin#6434 - bitcoin/bitcoin#6372 - bitcoin/bitcoin#6447 - bitcoin/bitcoin#6149 - bitcoin/bitcoin#6468 Part of #2074.
Bitcoin 0.12 misc PRs 1 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6198 - bitcoin/bitcoin#6206 - bitcoin/bitcoin#5927 - bitcoin/bitcoin#6213 - bitcoin/bitcoin#6061 - bitcoin/bitcoin#6283 (partial, remainder was pulled in #929) - bitcoin/bitcoin#6272 - bitcoin/bitcoin#6316 - bitcoin/bitcoin#6133 - bitcoin/bitcoin#6387 - bitcoin/bitcoin#6401 - bitcoin/bitcoin#6434 - bitcoin/bitcoin#6372 - bitcoin/bitcoin#6447 - bitcoin/bitcoin#6149 - bitcoin/bitcoin#6468 Part of #2074.
Bitcoin 0.12 misc PRs 1 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6198 - bitcoin/bitcoin#6206 - bitcoin/bitcoin#5927 - bitcoin/bitcoin#6213 - bitcoin/bitcoin#6061 - bitcoin/bitcoin#6283 (partial, remainder was pulled in #929) - bitcoin/bitcoin#6272 - bitcoin/bitcoin#6316 - bitcoin/bitcoin#6133 - bitcoin/bitcoin#6387 - bitcoin/bitcoin#6401 - bitcoin/bitcoin#6434 - bitcoin/bitcoin#6372 - bitcoin/bitcoin#6447 - bitcoin/bitcoin#6149 - bitcoin/bitcoin#6468 Part of #2074.
Bitcoin 0.12 misc PRs 1 Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#6198 - bitcoin/bitcoin#6206 - bitcoin/bitcoin#5927 - bitcoin/bitcoin#6213 - bitcoin/bitcoin#6061 - bitcoin/bitcoin#6283 (partial, remainder was pulled in #929) - bitcoin/bitcoin#6272 - bitcoin/bitcoin#6316 - bitcoin/bitcoin#6133 - bitcoin/bitcoin#6387 - bitcoin/bitcoin#6401 - bitcoin/bitcoin#6434 - bitcoin/bitcoin#6372 - bitcoin/bitcoin#6447 - bitcoin/bitcoin#6149 - bitcoin/bitcoin#6468 Part of #2074.
d16b7b2 Buffer log messages and explicitly open logs (random-zebra) Pull request description: implemented on top of - [x] #1449 - [x] #1437 - [x] #1439 Backports bitcoin#6149 > Prevents stomping on debug logs in datadirs that are locked by other instances and lost parameter interaction messages that can get wiped by ShrinkDebugFile(). The log is now opened explicitly and all emitted messages are buffered until this open occurs. The version message and log cut have also been moved to the earliest possible sensible location. ACKs for top commit: furszy: utACK d16b7b2 Fuzzbawls: ACK d16b7b2 Tree-SHA512: f3f859181499661641df1ccf118fdb583517c3f4104313df4c200471436e2c456bd9d15164215cfde274b235afdd2afe19a186c214d3c06461f0e3a03bd944b8
Prevents stomping on debug logs in datadirs that are locked by other
instances and lost parameter interaction messages that can get wiped by
ShrinkDebugFile().
The log is now opened explicitly and all emitted messages are buffered
until this open occurs. The version message and log cut have also been
moved to the earliest possible sensible location to prevent messages from
appearing "before the cut."
Thanks @jgarzik for setting me on the right track.