Skip to content

init: avoid pointing to a disabled debug log on failure - #37034

Open
l0rinc wants to merge 2 commits into
bitcoin:masterfrom
l0rinc:l0rinc/no-log-file-errors
Open

l0rinc wants to merge 2 commits into
bitcoin:masterfrom
l0rinc:l0rinc/no-log-file-errors

Conversation

@l0rinc

@l0rinc l0rinc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Problem: When startup fails under -daemonwait, the daemon points to the debug log for details.
With -nodebuglogfile, that hint reads check for details, and fatal errors also include an empty log reference before the cause.

Fix: When file logging is disabled, suggest running in the foreground for startup details and report the fatal error directly.

Reproduce the daemon message on Unix
build/bin/bitcoind -regtest -datadir="$(mktemp -d)" -daemonwait -nodebuglogfile -pid=missing/bitcoind.pid

With the fix, this prints Error during initialization - run in the foreground for details.
Without -daemonwait, the error names the PID file the node couldn't create.

Exercise a daemon startup failure and a fatal index error with -nodebuglogfile, which currently leaves an empty filename in both messages.
When file logging is disabled, direct daemon users to the foreground startup error and omit the log hint from fatal errors, which already include the cause.
@DrahtBot

DrahtBot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK jeanpablojp

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #35911 (Warn on and add missing [[noreturn]] by fanquake)
  • #35355 (Use atomics for determining whether trace logging is enabled by ajtowns)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@jeanpablojp jeanpablojp left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

tACK fbac7f0

Comment thread src/bitcoind.cpp
exit(EXIT_SUCCESS);
} else { // fRet = false or token read error (premature exit).
tfm::format(std::cerr, "Error during initialization - check %s for details\n", fs::PathToString(LogInstance().m_file_path.filename()));
const auto hint{LogInstance().m_print_to_file ? strprintf("check %s", fs::PathToString(LogInstance().m_file_path.filename())) : "run in the foreground"};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

With file logging on, the new test's PID failure says check debug.log for details, but the child fails before StartLogging, so the error never reaches the log file, with or without this PR.

Suggested change
const auto hint{LogInstance().m_print_to_file ? strprintf("check %s", fs::PathToString(LogInstance().m_file_path.filename())) : "run in the foreground"};
const auto hint{LogInstance().m_print_to_file ? strprintf("check %s or run in the foreground", fs::PathToString(LogInstance().m_file_path.filename())) : "run in the foreground"};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants