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

Buffer log messages and explicitly open logs #6149

Merged
merged 1 commit into from Jul 22, 2015

Conversation

ajweiss
Copy link
Contributor

@ajweiss ajweiss commented May 16, 2015

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.

@laanwj
Copy link
Member

laanwj commented May 16, 2015

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)

@ajweiss ajweiss force-pushed the ajw_1505_early_log_buffer branch from 945ad84 to 784804a Compare May 18, 2015
@ajweiss
Copy link
Contributor Author

ajweiss commented May 18, 2015

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.

@ajweiss ajweiss force-pushed the ajw_1505_early_log_buffer branch from 784804a to cd5ef83 Compare May 19, 2015
*/
static FILE* fileout = NULL;
static boost::mutex* mutexDebugLog = NULL;
static list<string> *vMsgsBeforeOpenLog;

int LogWriteStr(const std::string &str)
Copy link
Member

@laanwj laanwj Jun 1, 2015

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

Copy link
Member

@laanwj laanwj Jun 1, 2015

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.

@laanwj
Copy link
Member

laanwj commented Jul 2, 2015

Needs nits addressed, should otherwise be ready for merging.

@ajweiss ajweiss force-pushed the ajw_1505_early_log_buffer branch from cd5ef83 to a1b25a3 Compare Jul 7, 2015
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.
@ajweiss ajweiss force-pushed the ajw_1505_early_log_buffer branch from a1b25a3 to 27d7605 Compare Jul 7, 2015
@ajweiss
Copy link
Contributor Author

ajweiss commented Jul 7, 2015

Nits addressed and rebased. Waiting for Travis... (which appears to be attempting to build the whole depends tree?)

@jgarzik
Copy link
Contributor

jgarzik commented Jul 7, 2015

lightly tested ACK

@laanwj
Copy link
Member

laanwj commented Jul 22, 2015

Tested ACK

@laanwj laanwj merged commit 27d7605 into bitcoin:master Jul 22, 2015
1 check passed
laanwj added a commit that referenced this issue Jul 22, 2015
27d7605 Buffer log messages and explicitly open logs (Adam Weiss)
Fuzzbawls added a commit to PIVX-Project/PIVX that referenced this issue Apr 6, 2020
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
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants