Skip to content

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

Closed
jrmithdobbs wants to merge 5 commits into
bitcoin:masterfrom
jrmithdobbs:fix-largefile-support-on-32bit-builds
Closed

jrmithdobbs wants to merge 5 commits into
bitcoin:masterfrom
jrmithdobbs:fix-largefile-support-on-32bit-builds

Conversation

@jrmithdobbs

Copy link
Copy Markdown
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? :)

@jgarzik

jgarzik commented Jul 31, 2011

Copy link
Copy Markdown
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.

@jrmithdobbs

Copy link
Copy Markdown
Contributor Author

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?

@jrmithdobbs

Copy link
Copy Markdown
Contributor Author

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.

@jgarzik

jgarzik commented Jul 31, 2011

Copy link
Copy Markdown
Contributor

Windows supports _ftelli64.

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

@jrmithdobbs

Copy link
Copy Markdown
Contributor Author

There we go, race condition gone.

@gavinandresen

Copy link
Copy Markdown
Contributor

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

@jrmithdobbs

Copy link
Copy Markdown
Contributor Author

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.

@jrmithdobbs

Copy link
Copy Markdown
Contributor Author

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.

@alexwaters

Copy link
Copy Markdown
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.

@laanwj

laanwj commented Nov 26, 2011

Copy link
Copy Markdown
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.

@sipa

sipa commented Apr 8, 2012

Copy link
Copy Markdown
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?

@laanwj

laanwj commented May 15, 2012

Copy link
Copy Markdown
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.

@Diapolo

Diapolo commented May 15, 2012

Copy link
Copy Markdown

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

@jrmithdobbs

Copy link
Copy Markdown
Contributor Author

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.

@Diapolo

Diapolo commented May 15, 2012

Copy link
Copy Markdown

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

dexX7 added a commit to dexX7/bitcoin that referenced this pull request Dec 18, 2016
…are cached

11c007e Fix incorrect value from getTotalTokens when fees are cached (zathras-crypto)
ptschip pushed a commit to ptschip/bitcoin that referenced this pull request Apr 12, 2017
some whitespace fixups to less commonly modified files
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Oct 16, 2019
Updating links to match new website directory
@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.

7 participants