mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
torcontrol: Improve connection logging #36759
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36759
Loading…
Reference in a new issue
No description provided.
Delete branch "prevent-tor-log-spam"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Before
eae193e750, Connect() only started the connection and returned true. If tor wasn't running the refusal was reported later and only logged under -debug=tor. Sinceeae193e750(in v32), every failed reconnect attempt logs:On a default configured node without tor, this pollutes debug.log with 18 lines every hour.
This improves it
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.
🟠 Minor · Configured Tor control failures lose the
connect()error reason at default log levelsWhen explicitly configured Tor control connections fail with a socket error, default logging now gives only a generic warning instead of the OS reason, such as connection refusal.
Location:
src/torcontrol.cpp:109(head).🔵 Suggestion · Connection-failure test misses both log-suppression paths
The new test would still pass if unconfigured Tor control attempts warned or configured attempts warned on every retry, leaving the PR's main log-suppression behavior unprotected.
Location:
test/functional/feature_torcontrol.py:302(head).Review coverage was incomplete.
Reviewed:
4ec95781e0c8· Review report · Previous reportspermalink
ACK
ac6d31e7a9cc @fjahr @pinheadmz
I've noticed these annoying warnings as well on my own node without tor and looked into it. There is an exponential backoff with limit of
RECONNECT_TIMEOUT_MAX{600.0}; // 10 min capso after ~20 minutes or so the log messages drop to once every ten minutes. We keep attempting this connection so that if the user starts tor later in the node's lifetime, we just pick it up and work with it.Personally I think it's annoying when you first start the node but then I dont mind seeing the attempts 6x/hour. Reminds me I need to start tor!
So I need help understanding the motivation for this change.
Why did you change this line? I think it actually shouldn't matter, its just residue of how all of our socket handling code has the perspective of bitcoin p2p even when that's not what we're doing with the socket.
Because it is used only on:
Setting it to false makes it log as debug, otherwise it would still log "connect() to 127.0.0.1:9051 failed after wait: Connection refused (111)"
My main motivation is that it can be confusing for users that are not running tor since it is a warning level message they might think it is a config error or open new issue (#36691) and also pollutes logs. If the user wants to see tor debug logs they can set -debug=tor like it was before v32
ACK
ac6d31e7a9Built and tested on macos/arm64. Code changes are justified and makes the logs cleaner / more like pre-32 behavior. Thanks @ViniciusCestarii for answering my questions!
Also wanted to throw out the option of using the new
LogWarnThenDebug()if you think that makes sense. Happy to re review.Show Signature
pinheadmz's public key is on openpgp.org
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.
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:
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.
If we decide to do this, we should probably also backport into 32.x.
tested ACK
ac6d31e7a9successfully built and tested with
clang++-20on Debian, targetingx86_64.logs looks less noisy (quite peaceful now) when i ran
bitcoindwith-printtoconsolere: https://github.com/bitcoin/bitcoin/pull/36759#pullrequestreview-5791717944
LogWarnThenDebugstrikes a balance between various user needs, i think it is OK to take it up. the log message that shows failure to connect to tor control is logged exactly once. logs will look sth like this:logs
I agree that the current behavior isn't ideal but it seems that an bigger problem than noisy logs is that you wouldn't see any logs unless you had
-debug=torif you had-torcontrolset explicitly, i.e. you clearly want to use Tor but there is an issue and it doesn't work. That's why I think the current v32 behavior was an improvement to the previous behavior. Instead of reverting, I would suggest a more complete fix that works well for both scenarios: When the user configured Tor they should see logs and when they didn't they should not see them (only with-debug=tor).I have drafted the change so people can decide if they like this more: https://github.com/fjahr/bitcoin/commits/2026-11-torlog/ But note that this also includes a bit of additional improvements like making the logging less noisy when it does happen and deals with losing the connection along the way.
Thanks for reviewing! I agree that logging for tor users is useful. I like @fjahr proposal but also tor is meant to work out of box (without the need of any explicit config), so users that never set tor specific config would not know that tor isn't being used unless they run with
-debug=tor.The best both worlds would be what @fjahr proposed + if no explicit tor config, log the first failure once at info level (e.g. "Not using Tor (no control port at 127.0.0.1:9051)") similar to @pinheadmz's
LogWarnThenDebug()but at info.@fjahr if you're OK with it, I can pull your commits into this PR (keeping you as author) and add the info-once part on top. Or if you'd rather open your own PR, I'll close this one in favor of it.
Sure, go ahead!
Force-pushed
d5f6a9b6c9adding @fjahr proposed changes + log the first failure once at info level. Updated PR title and description.I think this has gotten perhaps too complicated. Even with Claude making me a chart I can't wrap my head around all the details:
LogWarnThenDebug()but for Info level and then debug (I think?)I think we should discuss simpler logic that cleans up the log and still follows the guidelines about log level.
I "generated" a commit along with @fjahr "lost connection" commit here: https://github.com/bitcoin/bitcoin/compare/master...pinheadmz:bitcoin:torcontrol-log-simple
Tested by turning tor on and off during / before bitcoind. This feels right to me:
default user
start with tor:
Got tor service ID...break tor:
Lost connection...(only once)restart tor:
Got tor service ID...start without tor:
restart tor:
Got service ID...break tor:
Lost connection...(only once)-listenonion / -torcontrol / -torpassword user
Same as default, plus a single
[warning] tor: Error connecting to address...the first time any connection attempt fails (at startup if tor isn't running, or on the first reconnect attempt after tor breaks). Never repeated for the lifetime of the process.-debug user
logs every single retry attempt
996846efe6I feel like the value should keep the name
m_tor_control_configuredthat is declared byinit.cpp. "Manual" connection doesn't make sense to me in the tor control context. For that matter, I also feel like the the value in netbase could probably also be renamedlog_as_info(orverbose_failure) or something because it has no effect untilLogConnectFailure()is called which could be called by P2P, torcontrol, Proxy, even bitcoin-cli...Agree it should be renamed, but it's out of scope here. I could do it as follow up
Thanks for reviewing! Force-pushed
ffd928d32dwith @pinheadmz suggested commits. I agree with renamingtor_control_configuredand that net logs were "leaking".This drops the info log on
d5f6a9b6c9, which purpose was to remind a default user that wanted tor to activate tor. Fine leaving it out to keep this simple.The only behavior changes from my suggested changes earlier is 1. dropping
ConnectDirectly(..., /*manual_connection=*/false)to prevent logging the failure reason when tor is configured (which I would prefer to keep). 2. ReplaceLogWarningwithLogWarnThenDebug(where I also think being more noisy would be better, it's also more in line with our logging behavior for similar cases like-proxy,-i2psametc.). The rest is basically just the variable rename. I also don't see how this is any less complicated than what I suggested. It seems you just didn't like the last commit and for the rest inline comments would have been a better choice allowing for deeper discussion on these changes? It seems claude mostly reimplemented my suggestions with minor improvements but didn't give me credit for it.Sorry @fjahr I'm not trying to step on toes or take credit, I didn't intend for the author to merge my commit, I just wanted to start a discussion:
And since its "just" logging I'm not dying on any hill here, and just asked claude to whip up something I could test out the user experience.
So just to take it back a step, here's things I like a lot:
Something I don't care about but won't oppose:
debug=toris the only configuration this PR should react to)Something I don't like but don't care enough to push back against if out-voted:
manual_connection=trueso that every error is logged a second time from netbaseMy goal was only to stop the log spam for users who don't run tor and both versions do that. Since @pinheadmz said they wouldn't oppose the config-dependent behavior or
manual_connection, I'll go back to @fjahr's version (manual_connection=tor_control_configuredandLogWarning), keeping thetor_control_configuredrename. I'll add @fjahr as author accordingly. Happy to switch if anyone objects.Force-pushed
11486ab3c8as mentioned in https://github.com/bitcoin/bitcoin/pull/36759#issuecomment-6802509280Concept ACK, this log is indeed noisy.
Should be behind a category.
Yes, this seems like a good candidate for
LogWarnThenDebugto me. I'd prefer that over a single LogDebug here.There seems to be consensus for this now and I am fine with switching to
LogWarnThenDebughere. As I mentioned, my concern was that torcontrol would then log differently from similar options like-proxyand-i2psam, which still log every failed attempt. I opened #36969 which usesLogWarnThenDebugto address this.Netbase and the caller logging the same failure at different levels is not great. With
LogWarnThenDebugI guess it makes sense to passfalsehere, #36969 does the same for the proxies. What I wanted to keep is the failure reason, which then only shows up with-debug=netand that did seem to feel right. What makes this annoying is thatConnectDirectly()picks the log level while only the caller knows how much the failure matters, so I am suggesting to removemanual_connectionentirely and return the reason to the caller instead which then can choose the log level, feedback welcome: #36970nit: Could switch to the local
argshere instead ofgArgsif you retouch.Thanks for the reviews! It seems consensus was reached so I force-pushed
bd9945c1a5to useLogWarnThenDebuginstead ofLogWarning, setmanual_connection=falseback and also addressed nit https://github.com/bitcoin/bitcoin/pull/36759#discussion_r4681418560.Done in
bd9945c1a5As this stands now the initial warning log doesn't have a reference to Tor anymore so users might miss it or find it confusing:
[warning] Error connecting to address 127.0.0.1:9051. Keeping the prefix would work but it would make the debug output a bit ugly:[tor] tor: Error connecting.... I would suggest making the message itself a bit more precise and mentioning Tor explicitly (ideally aligning the message below as well).I also looked into fixing this on the macro level itself since this could be a general problem but the other call sides are not as severe for different reasons and I wouldn't want to change the output generally here since logging is a hotly debated topic.
Thanks @fjahr for the review! Force-pushed
4ec95781e0addressing https://github.com/bitcoin/bitcoin/pull/36759#discussion_r4701408342Well spotted, done in
4ec95781e0. It looks nicerACK
4ec95781e0ACK
4ec95781e0Reviewed and tested. Cleaner logs for most users, more verbose logs for interested tor users and even more for debug users. Very nice and thanks for going back and forth a few times!
Show Signature
pinheadmz's public key is on openpgp.org
ACK
4ec95781e0ACK
4ec95781e0. code reviewed and testedsuccessfully built and tested with
clang++-20on Debian, targetingx86_64why do we need to assert on this ?
that log comes from
netbase.cpprather than torcontrol, so the test now depends on wording and a debug category outside this PR. I think the[warning] Error connecting to Tor control port ...assertion already covers the new behavior just fineI agree, but it's harmless and this is merged now, so I'd leave it as is.
Possibly related CI failure: https://github.com/bitcoin/bitcoin/actions/runs/46929464856/job/143633649485#step:11:1
Damn ya know what I was looking at the
port = self.next_port()line intest_connect_failure_warning()and was suspicious that other tests running in parallel would conflict. Claude told me not to worry:I'm sorry I should have brought it up during review. Claude wants to apologize too:
Opened #37075 for fixing it