Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jul 19, 2024

NOLINT(bitcoin-unterminated-logprintf) is used to document a missing trailing \n char in the format string. This has many issues:

  • It is just documentation, assuming that a trailing \n ends up in the formatted string. It is not enforced at compile-time, so it is brittle.
  • If the newline was truly missing and NOLINT(bitcoin-unterminated-logprintf) were used to document a "continued" line, the log stream would be racy/corrupt, because any other thread may inject a log message in the meantime.
  • If the newline was accidentally missing, nothing is there to correct the mistake.
  • The intention of all code is to always end a log line with a new line. However, historic code exists to deal with the case where the new line was missing (m_started_new_line). This is problematic, because the presumed dead code has to be maintained (Early logging improvements #30386 (comment)).

Fix almost all issues by removing the NOLINT(bitcoin-unterminated-logprintf), ensuring that a new line is always present.

A follow-up will remove the dead logging code.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 19, 2024

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK TheCharlatan, ryanofsky
Concept ACK luke-jr

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@@ -100,7 +100,7 @@ class CBitcoinLevelDBLogger : public leveldb::Logger {

assert(p <= limit);
base[std::min(bufsize - 1, (int)(p - base))] = '\0';
LogPrintLevel(BCLog::LEVELDB, BCLog::Level::Debug, "%s", base); // NOLINT(bitcoin-unterminated-logprintf)
LogDebug(BCLog::LEVELDB, "%s\n", util::RemoveSuffixView(base, "\n"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably, this is a "bugfix" to add a missing \n in the unlikely case where the buffer is exactly filled and the last character is overwritten from \n to \0.

However, I am not sure if anyone ever ran into this logging bug, so I am just leaving a comment here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It is possible to test this "bugfix" by reducing both buffer sizes sufficiently and then running with -debug=leveldb -printtoconsole)

Copy link
Contributor

@TheCharlatan TheCharlatan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK fa18fc7

@fanquake fanquake requested a review from theuni July 25, 2024 11:10
Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Aug 1, 2024
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK fa18fc7

@DrahtBot DrahtBot requested a review from luke-jr August 6, 2024 18:29
@ryanofsky ryanofsky merged commit bb25e06 into bitcoin:master Aug 6, 2024
@maflcko maflcko deleted the 2407-log-lint branch August 7, 2024 07:17
@bitcoin bitcoin locked and limited conversation to collaborators Aug 7, 2025
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.

5 participants