Fix >2GB debug.log on 32bit and trunc'ing debug.log on all platforms #439

pull jrmithdobbs wants to merge 5 commits into bitcoin:master from jrmithdobbs:fix-largefile-support-on-32bit-builds changing 4 files +20 −22
  1. jrmithdobbs commented at 10:11 PM on July 30, 2011: contributor

    This patch does two bug fixing things and has two documentation corrections:

    bug fix 1) It allows 32bit builds to write to debug.log past 2GB. I need someone to test this on bsd and win32. bug fix 2) Change GetFilesize to use stat() instead of fseek() to prevent an integer overflow that would prevent >2GB debug.logs from getting trimmed on most (any?) platforms. This function is only currently called by ShrinkDebugFile which has been updated to pass a string instead of a FILE.

    documentation update) Add -logtimestamps and -printtoconsole to -? output.

    This can be tested with:

    dd if=/dev/zero of=debug.log bs=$((1024 * 1024)) count=2048; tail -f debug.log & bitcoind -daemon;

    If logs get appended to where debug.log continues past 2GB it is working. Must be tested on a 32bit build.

    debug.log should also no longer be truncated on startup as that should be left to the user. This can be tested by restarting bitcoind after the fact and ensuring it is not truncated.

    The additional help output is pretty straight forward to test: is it there? :)

  2. Add makefile.unix definitions (tested on glibc, not sure if *bsd libc support these options) to allow debug.log to grow past 2GB on 32bit builds. 93b21468f5
  3. Fix integer overflow in GetFilesize by using stat() instead of fseek(). e0363fc6b0
  4. Document some undocumented debug.log options. 9a1f630380
  5. jgarzik commented at 12:28 AM on July 31, 2011: contributor

    Your GetFileSize change is a regression, introducing a minor race window. If we have an open FILE*, then we may fstat via fileno. The current code implicitly does this, by working on the already-open file.

    Your change refers to the file by name, which may have been renamed, and may no longer refer to the already-open file.

  6. jrmithdobbs commented at 12:30 AM on July 31, 2011: contributor

    win32 does not have a fstat() that I can find. That is why I did it this way. There doesn't seem to be a way to easily guarantee that fseek()/ftell() will give you a 64bit int. Suggestions?

  7. jrmithdobbs commented at 12:42 AM on July 31, 2011: contributor

    Also it actually doesn't add any new kind of race condition. It's only first opened a line before the call (and this is the only caller) and gets closed and reopened immediately afterwards if the file with that filename at the time is longer than the specified hardcoded value.

    Worst case we'll get old logs from a different file appended to the top of the new debug.log than was actually in the old debug.log we had opened if a user changes debug.log between open and Getfilesize call. Since the contents of debug.log are never parsed by bitcoin it doesn't add any form of attack/dos vector that isn't accomplished by just rm debug.log which you would have to already be able to perform in order to take advantage.

  8. jgarzik commented at 1:38 AM on July 31, 2011: contributor

    Windows supports _ftelli64.

    The ftell approach remains superior because it avoids the aforementioned regression.

  9. Don't open debug.log until we've checked size. 6fedea08db
  10. jrmithdobbs commented at 2:25 AM on July 31, 2011: contributor

    There we go, race condition gone.

  11. Dont bother saving previous debug.log output. On a busy node we write ~1MB/minute anyhow. 6d7244d652
  12. gavinandresen commented at 3:49 PM on August 9, 2011: contributor

    Seems to me this is fixing the symptom, not the disease. The disease is writing way too much to debug.log by default.

  13. jrmithdobbs commented at 11:29 PM on August 9, 2011: contributor

    I agree that the default logging level probably needs to be reworked; but, this is a problem in itself. No software should just stop logging out of the blue unless it has no space on the device it's logging to.

  14. jrmithdobbs commented at 4:23 PM on September 7, 2011: contributor

    Added test instructions to description:

    This can be tested with:

    dd if=/dev/zero of=debug.log bs=$((1024 * 1024)) count=2048; tail -f debug.log & bitcoind -daemon;

    If logs get appended to where debug.log continues past 2GB it is working. Must be tested on a 32bit build.

  15. alexwaters commented at 8:25 AM on September 18, 2011: contributor

    I have to agree that we shouldn't have a 2GB+ logfile in the first place. For the majority of people, I would think that the advantage of having verbose logs is outweighed by the inconvenience of their size.

    #515 - logfile size reference

    #125 - log filters #520 - streamlining the output

    I'm definitely not qualified to appreciate the inner-workings of the logfile. That being said, I would think a 2GB cap is sensible (intentional or not). Please correct me if I'm mistaken.

  16. laanwj commented at 8:11 AM on November 26, 2011: member

    I agree with @jrmithdobbs here. >2GB log files are a problem in itself, but it should not simply stop logging after that, that can be dangerous and lead to non-debuggable issues.

  17. sipa commented at 5:15 PM on April 8, 2012: member

    This seems to have been forgotten over time. Looking at it again, it seems to remove the automatic pruning of debug.log. Is this intentional/wanted?

  18. laanwj commented at 7:49 AM on May 15, 2012: member

    Hm I understood from the bug reported was that it stopped logging after 2Gb. It's good to solve that.

    Auto-pruning should not be disabled though, IMO, as most users don't want to be concerned with the debug.log file at all. So having it grow to fill their disk is not so nice. Pruning at startup when the file is big is a good compromise.

  19. Diapolo commented at 12:37 PM on May 15, 2012: none

    But processing a 2GB file should be quite time-intense and will for sure hurt user-experience!?

  20. jrmithdobbs commented at 1:30 PM on May 15, 2012: contributor

    Processing how? It's never read back in let alone "processed."

    My removing of the pruning was intentional. Auto-pruning logs is just bad practice. What if I need to look at something in my log from a month ago? Things log way too verbosely by default, sure, fix that don't mangle the log.

    Feel free to close this. It needs fixing but I have no interest in rebasing/etc.

  21. Diapolo commented at 2:50 PM on May 15, 2012: none

    I meant Auto-pruning a large log-file could be time-intense, no?

  22. gavinandresen closed this on May 18, 2012

  23. dexX7 referenced this in commit a377a32759 on Dec 18, 2016
  24. ptschip referenced this in commit 5b5f29f4df on Apr 12, 2017
  25. lateminer referenced this in commit 9593213c70 on Oct 16, 2019
  26. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-19 00:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me