Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Buffer log messages and explicitly open logs #6149
Prevents stomping on debug logs in datadirs that are locked by other
The log is now opened explicitly and all emitted messages are buffered
Thanks @jgarzik for setting me on the right track.
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)
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.