torcontrol: Improve connection logging #36759

Manually merged
ViniciusCestarii merged 2 commits from prevent-tor-log-spam into master 2026-12-02 13:45:49 +00:00 AGit
ViniciusCestarii commented 2026-11-04 16:36:47 +00:00 (Migrated from github.com)

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. Since eae193e750 (in v32), every failed reconnect attempt logs:

2026-11-04T14:14:08Z connect() to 127.0.0.1:9051 failed after wait: Connection refused (111)
2026-11-04T14:14:08Z [warning] tor: Error connecting to address 127.0.0.1:9051
2026-11-04T14:14:08Z [warning] tor: Initiating connection to Tor control port 127.0.0.1:9051 failed

On a default configured node without tor, this pollutes debug.log with 18 lines every hour.

This improves it

Before eae193e750235e4023b3e6313284eede2cd7a022, Connect() only started the connection and returned true. If tor wasn't running the refusal was reported later and only logged under -debug=tor. Since eae193e750 (in v32), every failed reconnect attempt logs: ``` 2026-11-04T14:14:08Z connect() to 127.0.0.1:9051 failed after wait: Connection refused (111) 2026-11-04T14:14:08Z [warning] tor: Error connecting to address 127.0.0.1:9051 2026-11-04T14:14:08Z [warning] tor: Initiating connection to Tor control port 127.0.0.1:9051 failed ``` On a default configured node without tor, this pollutes debug.log with 18 lines every hour. This improves it
First-time contributor

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 levels

When 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 reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:806938d40e279b6d701b2e78128bb1a09b55193a0b697245a1dce6241d3081c1:3607c760b63c01fb7f1f349adfc3fd0614b148a7df02e42f2f0edc2d448925a1 --> <!-- ralph-base:0e8f70a86314bc73539b110d947c41d40c4886fc --> <!-- ralph-head:4ec95781e0c8fed7577f661bbe04967bea76365d --> <!-- ralph-case:4ee378811f804b2bca0a35267f5976ff79083cc3045385b3f34da30b9e169b2a --> 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 levels** When 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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/4ec95781e0c8fed7577f661bbe04967bea76365d/src/torcontrol.cpp#L109>) (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`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/4ec95781e0c8fed7577f661bbe04967bea76365d/test/functional/feature_torcontrol.py#L302>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`4ec95781e0c8`](<https://git.fish.foo/bitcoin/bitcoin/commit/4ec95781e0c8fed7577f661bbe04967bea76365d>) · [Review report](<https://review.fish.foo/report/36759-4ec95781e0c8fed7577f661bbe04967bea76365d-3198-7.html>) · [Previous reports](<https://review.fish.foo/traces/36759/>) [permalink](<https://review.fish.foo/report/36759-4ec95781e0c8fed7577f661bbe04967bea76365d-3198-7.html>)
jpk68 commented 2026-11-04 18:40:30 +00:00 (Migrated from github.com)
ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65
fanquake commented 2026-11-04 18:48:46 +00:00 (Migrated from github.com)

cc @fjahr @pinheadmz

cc @fjahr @pinheadmz
pinheadmz (Migrated from github.com) reviewed 2026-11-04 19:07:49 +00:00
pinheadmz (Migrated from github.com) left a comment

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 cap so 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.

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 cap` so 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.
pinheadmz (Migrated from github.com) commented 2026-11-04 19:03:03 +00:00

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.

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.
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-05 00:12:52 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-05 00:12:52 +00:00

Because it is used only on:

    if (manual_connection) {
        LogInfo("%s", error_message);
    } else {
        LogDebug(BCLog::NET, "%s", error_message);
    }

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)"

Because it is used only on: ``` if (manual_connection) { LogInfo("%s", error_message); } else { LogDebug(BCLog::NET, "%s", error_message); } ``` 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)"
ViniciusCestarii commented 2026-11-05 00:23:42 +00:00 (Migrated from github.com)

So I need help understanding the motivation for this change.

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

> So I need help understanding the motivation for this change. 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
pinheadmz (Migrated from github.com) approved these changes 2026-11-05 20:36:22 +00:00
pinheadmz (Migrated from github.com) left a comment

ACK ac6d31e7a9

Built 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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65
-----BEGIN PGP SIGNATURE-----

iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmrs6EcbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick6250P/2A3R5tuB0dFQVp//prO
MvcblYzRWR5XwS84Pq0lnJYWWgy2g5AtPnHx1Kxuy68VVuU2BCtA7c8Cniwaa3gb
yPZiBNswAksLjV5mwPiw8rBc3ht+D4Zplp1dpMaZKLM6lmBUJSMRjWE5U6dm7iGq
rPB9OWvja2qmPmInItoZcA0VXc0pMwMHm2SrHKFj0bVfAd5LeMnLU9j20zH7Z1eB
/mdSJ5fYiVJOfqNCh0wjDZh9YOswzpDxVOpLsSZ8AqzK70n6xJxfF//Oh53dSEvt
QZBYkUVmgR5JJXStEMbEV+xQimbwj9yXgqefix1W6hZjcteG5jQSZ5esU7r5AVAx
u64OrkAe1hJ1hKb1qK8a18SIv2Iuj4KdYOUoNdxdMGXBvOcKAZh6/gJCrAzIKt5D
S/UyvDicKPpzAJLGNhoAC5G7D2TttuOtWB6+Qod9KF91TufvLfhoVtEJGk/LiukQ
hi9cmPcq48mfdD7Oa39tDuoRMRmRDvSauM3tDdbkxV6eNo3VxrIJtrDeLO8djveA
6urwiVLbnbW9o/Lw+akMCVxHv5GcRy1jsjSON7zminnrX+8WeI6IA5Ayj53Nb/9I
s2KrNx/n2/CJ7hV24wcwAf5Uf2++pWlDO9B4hwlT3RzH458O/idUVtMBvY6KhqMP
knK0OD71w1vhpa5U4dtovh+4
=KbM6
-----END PGP SIGNATURE-----

pinheadmz's public key is on openpgp.org

ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65 Built 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. <details><summary>Show Signature</summary> ``` -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65 -----BEGIN PGP SIGNATURE----- iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmrs6EcbFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick6250P/2A3R5tuB0dFQVp//prO MvcblYzRWR5XwS84Pq0lnJYWWgy2g5AtPnHx1Kxuy68VVuU2BCtA7c8Cniwaa3gb yPZiBNswAksLjV5mwPiw8rBc3ht+D4Zplp1dpMaZKLM6lmBUJSMRjWE5U6dm7iGq rPB9OWvja2qmPmInItoZcA0VXc0pMwMHm2SrHKFj0bVfAd5LeMnLU9j20zH7Z1eB /mdSJ5fYiVJOfqNCh0wjDZh9YOswzpDxVOpLsSZ8AqzK70n6xJxfF//Oh53dSEvt QZBYkUVmgR5JJXStEMbEV+xQimbwj9yXgqefix1W6hZjcteG5jQSZ5esU7r5AVAx u64OrkAe1hJ1hKb1qK8a18SIv2Iuj4KdYOUoNdxdMGXBvOcKAZh6/gJCrAzIKt5D S/UyvDicKPpzAJLGNhoAC5G7D2TttuOtWB6+Qod9KF91TufvLfhoVtEJGk/LiukQ hi9cmPcq48mfdD7Oa39tDuoRMRmRDvSauM3tDdbkxV6eNo3VxrIJtrDeLO8djveA 6urwiVLbnbW9o/Lw+akMCVxHv5GcRy1jsjSON7zminnrX+8WeI6IA5Ayj53Nb/9I s2KrNx/n2/CJ7hV24wcwAf5Uf2++pWlDO9B4hwlT3RzH458O/idUVtMBvY6KhqMP knK0OD71w1vhpa5U4dtovh+4 =KbM6 -----END PGP SIGNATURE----- ``` pinheadmz's public key is [on openpgp.org](https://keys.openpgp.org/vks/v1/by-fingerprint/E61773CD6E01040E2F1BD78CE7E2984B6289C93A) </details>
DrahtBot commented 2026-11-05 20:36:25 +00:00 (Migrated from github.com)

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 fjahr, pinheadmz, jpk68, winterrdog
Concept ACK ismaelsadeeq

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:

  • #36970 (RFC: netbase: Remove manual_connection and return the failure reason to callers by fjahr)
  • #36880 (init: Fix surprising behaviors of negated options by fjahr)
  • #36170 (net: stop sharing P2P listeners with automatic Tor services by l0rinc)

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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36759 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36759.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36759#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | ACK | [fjahr](https://github.com/bitcoin/bitcoin/pull/36759#issuecomment-7192275132), [pinheadmz](https://github.com/bitcoin/bitcoin/pull/36759#pullrequestreview-6138845270), [jpk68](https://github.com/bitcoin/bitcoin/pull/36759#issuecomment-7325010476), [winterrdog](https://github.com/bitcoin/bitcoin/pull/36759#pullrequestreview-6141599368) | | Concept ACK | [ismaelsadeeq](https://github.com/bitcoin/bitcoin/pull/36759#pullrequestreview-5875604908) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#36970](https://github.com/bitcoin/bitcoin/pull/36970) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36970.svg"></sub> (RFC: netbase: Remove manual_connection and return the failure reason to callers by fjahr) * [#36880](https://github.com/bitcoin/bitcoin/pull/36880) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36880.svg"></sub> (init: Fix surprising behaviors of negated options by fjahr) * [#36170](https://github.com/bitcoin/bitcoin/pull/36170) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36170.svg"></sub> (net: stop sharing P2P listeners with automatic Tor services by l0rinc) 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. <!--5faf32d7da4f0f540f40219e4f7537a3-->
fanquake commented 2026-11-05 21:05:32 +00:00 (Migrated from github.com)

If we decide to do this, we should probably also backport into 32.x.

If we decide to do this, we should probably also backport into 32.x.
winterrdog (Migrated from github.com) reviewed 2026-11-05 23:15:17 +00:00
winterrdog (Migrated from github.com) left a comment

tested ACK ac6d31e7a9

successfully built and tested with clang++-20 on Debian, targeting x86_64.


logs looks less noisy (quite peaceful now) when i ran bitcoind with -printtoconsole

re: https://github.com/bitcoin/bitcoin/pull/36759#pullrequestreview-5791717944

LogWarnThenDebug strikes 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
...
2026-11-05T22:59:01Z torcontrol thread start
2026-11-05T22:59:01Z initload thread exit
2026-11-05T22:59:01Z [warning] Error connecting to address 127.0.0.1:9051
2026-11-05T22:59:01Z [warning] Initiating connection to Tor control port 127.0.0.1:9051 failed
2026-11-05T22:59:01Z Bound to 127.0.0.1:18445
2026-11-05T22:59:01Z Bound to [::]:18444
2026-11-05T22:59:01Z Bound to 0.0.0.0:18444
2026-11-05T22:59:01Z Loaded 0 addresses from "anchors.dat"
...
tested ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65 successfully built and tested with `clang++-20` on Debian, targeting `x86_64`. --- logs looks less noisy (quite peaceful now) when i ran `bitcoind` with `-printtoconsole` re: https://github.com/bitcoin/bitcoin/pull/36759#pullrequestreview-5791717944 `LogWarnThenDebug` strikes 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: <details open><summary>logs</summary> ```text ... 2026-11-05T22:59:01Z torcontrol thread start 2026-11-05T22:59:01Z initload thread exit 2026-11-05T22:59:01Z [warning] Error connecting to address 127.0.0.1:9051 2026-11-05T22:59:01Z [warning] Initiating connection to Tor control port 127.0.0.1:9051 failed 2026-11-05T22:59:01Z Bound to 127.0.0.1:18445 2026-11-05T22:59:01Z Bound to [::]:18444 2026-11-05T22:59:01Z Bound to 0.0.0.0:18444 2026-11-05T22:59:01Z Loaded 0 addresses from "anchors.dat" ... ``` </details>
fjahr commented 2026-11-06 02:04:16 +00:00 (Migrated from github.com)

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=tor if you had -torcontrol set 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.

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=tor` if you had `-torcontrol` set 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.
ViniciusCestarii commented 2026-11-06 12:20:11 +00:00 (Migrated from github.com)

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.

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.
fjahr commented 2026-11-07 10:12:20 +00:00 (Migrated from github.com)

if you're OK with it, I can pull your commits into this PR

Sure, go ahead!

> if you're OK with it, I can pull your commits into this PR Sure, go ahead!
ViniciusCestarii commented 2026-11-07 16:23:08 +00:00 (Migrated from github.com)

Force-pushed d5f6a9b6c9 adding @fjahr proposed changes + log the first failure once at info level. Updated PR title and description.

Force-pushed d5f6a9b6c96b30eaa9740eda5b9a98474a3aef59 adding @fjahr proposed changes + log the first failure once at info level. Updated PR title and description.
pinheadmz (Migrated from github.com) reviewed 2026-11-09 18:49:44 +00:00
pinheadmz (Migrated from github.com) left a comment

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:

  • There's messages logging at Warn, Info, and Debug levels.
  • There's torcontrol options being set manually and by default.
  • There's the user's log level setting at default (info) or debug.
  • There's first connection error and not-first error.
  • There's a re-implementation of LogWarnThenDebug() but for Info level and then debug (I think?)
  • Netbase and torcontrol both write logs, at different levels

I think we should discuss simpler logic that cleans up the log and still follows the guidelines about log level.

  1. Always set "manual" to false" netbase only logs debug. Handle more interesting logging directly from torcontrol
  2. Use LogWarnThenDebug instead of adding new state and effectively LogInfoThenDebug

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

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: - There's messages logging at Warn, Info, and Debug levels. - There's torcontrol options being set manually and by default. - There's the user's log level setting at default (info) or debug. - There's first connection error and not-first error. - There's a re-implementation of `LogWarnThenDebug()` but for Info level and then debug (I think?) - Netbase and torcontrol both write logs, at different levels I think we should discuss simpler logic that cleans up the log and still follows the guidelines about log level. 1. Always set "manual" to false" netbase only logs debug. Handle more interesting logging directly from torcontrol 2. Use LogWarnThenDebug instead of adding new state and effectively LogInfoThenDebug 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: <nothing> 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
pinheadmz (Migrated from github.com) commented 2026-11-09 15:52:56 +00:00

996846efe6

I feel like the value should keep the name m_tor_control_configured that is declared by init.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 renamed log_as_info (or verbose_failure) or something because it has no effect until LogConnectFailure() is called which could be called by P2P, torcontrol, Proxy, even bitcoin-cli...

996846efe6d0e7ee67d7fc7857321f46d26df1bc I feel like the value should keep the name `m_tor_control_configured` that is declared by `init.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 renamed `log_as_info` (or `verbose_failure`) or something because it has no effect until `LogConnectFailure()` is called which could be called by P2P, torcontrol, Proxy, even bitcoin-cli...
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-10 12:08:19 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-10 12:08:19 +00:00

Agree it should be renamed, but it's out of scope here. I could do it as follow up

Agree it should be renamed, but it's out of scope here. I could do it as follow up
ViniciusCestarii commented 2026-11-10 12:23:45 +00:00 (Migrated from github.com)

Thanks for reviewing! Force-pushed ffd928d32d with @pinheadmz suggested commits. I agree with renaming tor_control_configured and 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.

Thanks for reviewing! Force-pushed ffd928d32de2137ff7178847d078ade064671563 with @pinheadmz suggested commits. I agree with renaming `tor_control_configured` and that net logs were "leaking". This drops the info log on d5f6a9b6c96b30eaa9740eda5b9a98474a3aef59, which purpose was to remind a default user that wanted tor to activate tor. Fine leaving it out to keep this simple.
fjahr commented 2026-11-10 21:39:14 +00:00 (Migrated from github.com)

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

I "generated" a commit

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. Replace LogWarning with LogWarnThenDebug (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, -i2psam etc.). 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.

> 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 > I "generated" a commit The only behavior changes from my [suggested changes](https://github.com/fjahr/bitcoin/commits/2026-11-torlog/) 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. Replace `LogWarning` with `LogWarnThenDebug` (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`, `-i2psam` etc.). 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.
pinheadmz commented 2026-11-11 13:58:18 +00:00 (Migrated from github.com)

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:

I think we should discuss simpler logic that cleans up the log and still follows the guidelines about log level.

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:

  • (warn then debug) log the first time tor control disconnects, or on startup if its not available
  • (info) log again when tor control reconnects
  • (debug) move every connection retry (after the first) down a log level so its less spammy

Something I don't care about but won't oppose:

  • Changing logging behavior based on user configuration (my opinion is that debug=tor is 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:

  • setting manual_connection=true so that every error is logged a second time from netbase
> 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: > I think we should discuss simpler logic that cleans up the log and still follows the guidelines about log level. 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: - (warn then debug) log the first time tor control disconnects, or on startup if its not available - (info) log again when tor control reconnects - (debug) move every connection retry (after the first) down a log level so its less spammy Something I don't care about but won't oppose: - Changing logging behavior based on user configuration (my opinion is that `debug=tor` is 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: - setting `manual_connection=true` so that every error is logged a second time from netbase
ViniciusCestarii commented 2026-11-11 17:20:38 +00:00 (Migrated from github.com)

My 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_configured and LogWarning), keeping the tor_control_configured rename. I'll add @fjahr as author accordingly. Happy to switch if anyone objects.

My 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_configured` and `LogWarning`), keeping the `tor_control_configured` rename. I'll add @fjahr as author accordingly. Happy to switch if anyone objects.
ViniciusCestarii commented 2026-11-11 17:53:22 +00:00 (Migrated from github.com)
Force-pushed 11486ab3c8fc756fa9d8b93235be27b9cb11efe5 as mentioned in https://github.com/bitcoin/bitcoin/pull/36759#issuecomment-6802509280
ismaelsadeeq (Migrated from github.com) reviewed 2026-11-12 13:53:39 +00:00
ismaelsadeeq (Migrated from github.com) left a comment

Concept ACK, this log is indeed noisy.
Should be behind a category.

Concept ACK, this log is indeed noisy. Should be behind a category.
sedited commented 2026-11-12 14:10:15 +00:00 (Migrated from github.com)

(warn then debug) log the first time tor control disconnects, or on startup if its not available

Yes, this seems like a good candidate for LogWarnThenDebug to me. I'd prefer that over a single LogDebug here.

> (warn then debug) log the first time tor control disconnects, or on startup if its not available Yes, this seems like a good candidate for `LogWarnThenDebug` to me. I'd prefer that over a single LogDebug here.
fjahr (Migrated from github.com) reviewed 2026-11-24 19:48:47 +00:00
fjahr (Migrated from github.com) left a comment

this seems like a good candidate for LogWarnThenDebug

There seems to be consensus for this now and I am fine with switching to LogWarnThenDebug here. As I mentioned, my concern was that torcontrol would then log differently from similar options like -proxy and -i2psam, which still log every failed attempt. I opened #36969 which uses LogWarnThenDebug to address this.

setting manual_connection=true so that every error is logged a second time from netbase

Netbase and the caller logging the same failure at different levels is not great. With LogWarnThenDebug I guess it makes sense to pass false here, #36969 does the same for the proxies. What I wanted to keep is the failure reason, which then only shows up with -debug=net and that did seem to feel right. What makes this annoying is that ConnectDirectly() picks the log level while only the caller knows how much the failure matters, so I am suggesting to remove manual_connection entirely and return the reason to the caller instead which then can choose the log level, feedback welcome: #36970

> this seems like a good candidate for `LogWarnThenDebug` There seems to be consensus for this now and I am fine with switching to `LogWarnThenDebug` here. As I mentioned, my concern was that torcontrol would then log differently from similar options like `-proxy` and `-i2psam`, which still log every failed attempt. I opened #36969 which uses `LogWarnThenDebug` to address this. > setting `manual_connection=true` so that every error is logged a second time from netbase Netbase and the caller logging the same failure at different levels is not great. With `LogWarnThenDebug` I guess it makes sense to pass `false` here, #36969 does the same for the proxies. What I wanted to keep is the failure reason, which then only shows up with `-debug=net` and that did seem to feel right. What makes this annoying is that `ConnectDirectly()` picks the log level while only the caller knows how much the failure matters, so I am suggesting to remove `manual_connection` entirely and return the reason to the caller instead which then can choose the log level, feedback welcome: #36970
Lines 2319-2321
fjahr (Migrated from github.com) commented 2026-11-24 14:25:41 +00:00

nit: Could switch to the local args here instead of gArgs if you retouch.

nit: Could switch to the local `args` here instead of `gArgs` if you retouch.
ViniciusCestarii commented 2026-11-25 19:12:11 +00:00 (Migrated from github.com)

Thanks for the reviews! It seems consensus was reached so I force-pushed bd9945c1a5 to use LogWarnThenDebug instead of LogWarning, set manual_connection=false back and also addressed nit https://github.com/bitcoin/bitcoin/pull/36759#discussion_r4681418560.

Thanks for the reviews! It seems consensus was reached so I force-pushed bd9945c1a5656c7e39bad008951e6780e6654bd1 to use `LogWarnThenDebug` instead of `LogWarning`, set `manual_connection=false` back and also addressed nit https://github.com/bitcoin/bitcoin/pull/36759#discussion_r4681418560.
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-25 19:12:28 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-25 19:12:28 +00:00

Done in bd9945c1a5

Done in bd9945c1a5656c7e39bad008951e6780e6654bd1
fjahr (Migrated from github.com) reviewed 2026-11-25 22:04:20 +00:00
fjahr (Migrated from github.com) commented 2026-11-25 22:04:19 +00:00

As 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).

            LogWarnThenDebug(BCLog::TOR, "Error connecting to Tor control port %s", tor_control_center);

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.

As 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). ```suggestion LogWarnThenDebug(BCLog::TOR, "Error connecting to Tor control port %s", tor_control_center); ``` 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.
ViniciusCestarii commented 2026-11-26 12:29:02 +00:00 (Migrated from github.com)
Thanks @fjahr for the review! Force-pushed 4ec95781e0c8fed7577f661bbe04967bea76365d addressing https://github.com/bitcoin/bitcoin/pull/36759#discussion_r4701408342
ViniciusCestarii (Migrated from github.com) reviewed 2026-11-26 12:31:03 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-11-26 12:31:03 +00:00

Well spotted, done in 4ec95781e0. It looks nicer

2026-11-26T12:21:09Z [tor] Attempting to connect to Tor control port 127.0.0.1:9051
2026-11-26T12:21:09Z [tor] Error connecting to Tor control port 127.0.0.1:9051
2026-11-26T12:21:09Z [tor] Not connected to Tor control port 127.0.0.1:9051, retrying in 2.25 s
Well spotted, done in 4ec95781e0c8fed7577f661bbe04967bea76365d. It looks nicer ``` 2026-11-26T12:21:09Z [tor] Attempting to connect to Tor control port 127.0.0.1:9051 2026-11-26T12:21:09Z [tor] Error connecting to Tor control port 127.0.0.1:9051 2026-11-26T12:21:09Z [tor] Not connected to Tor control port 127.0.0.1:9051, retrying in 2.25 s ```
fjahr commented 2026-11-26 12:38:51 +00:00 (Migrated from github.com)
ACK 4ec95781e0c8fed7577f661bbe04967bea76365d
pinheadmz (Migrated from github.com) approved these changes 2026-12-01 19:50:22 +00:00
pinheadmz (Migrated from github.com) left a comment

ACK 4ec95781e0

Reviewed 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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

ACK 4ec95781e0c8fed7577f661bbe04967bea76365d
-----BEGIN PGP SIGNATURE-----

iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmsPJHYbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick6ukQQAN3LfTkNjhwlGo3lKqmf
ooxOIOuYd6Xe/uMej53M+ysSQW0On2zN6WUdUrFLAPv6ur0TDXZTi117hc7BvzbI
9d3f30RUZWYH8hD8GaSR5V1xD98yNrHJj1ptbyMNYCK8gyW8POcCTCywLTyRmzhw
kAP7zMH7o62Hy9hfutxQxfrmdogWk8In1ZS1Xv9qH1usfwJMyByEbYTKhr+JI7AS
psaxLm056royzsyKorhoEpebA9uRQc6MH6oRlhKLebxmhcSsgLLANP3ZljJ3QcAx
iz4t/MtoZY3b02C19Uax43LDBGh4P00Hoew1o7SzCKAQzjknlCnH2U91Hm8rOojI
QvPI27vWoy/mLXyCt7xtNG/qz0xedQM45CLmWFo2llAhgnJwuuMy/+WaJyeT7qmr
7RmUo/VWGbvUqlkxQ6qqYrcoyMFso8AQPePXJqU9aGfVKmgNezUyevxT5NjuwzRq
0EQv8QCUKQdL+ndB1C+SQeNs2yzkZ9ViW3158BIuEjvsKFvCxVgYn/xk8rboLcDJ
qWwACxaOn9TVQDH2hTyFK3YtECA47dgQeSYI5WMWsh/cJ8ecqpbyOvHro2/OaBsI
2FYxqohWYjqNvTY702iRaWR48IFYyldDOgqrFf5jjtoTlZAvoUEeApPl0ILw2+El
JNu8HbrQaVBFl79bU182YXOb
=Bt62
-----END PGP SIGNATURE-----

pinheadmz's public key is on openpgp.org

ACK 4ec95781e0c8fed7577f661bbe04967bea76365d Reviewed 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! <details><summary>Show Signature</summary> ``` -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 ACK 4ec95781e0c8fed7577f661bbe04967bea76365d -----BEGIN PGP SIGNATURE----- iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmsPJHYbFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick6ukQQAN3LfTkNjhwlGo3lKqmf ooxOIOuYd6Xe/uMej53M+ysSQW0On2zN6WUdUrFLAPv6ur0TDXZTi117hc7BvzbI 9d3f30RUZWYH8hD8GaSR5V1xD98yNrHJj1ptbyMNYCK8gyW8POcCTCywLTyRmzhw kAP7zMH7o62Hy9hfutxQxfrmdogWk8In1ZS1Xv9qH1usfwJMyByEbYTKhr+JI7AS psaxLm056royzsyKorhoEpebA9uRQc6MH6oRlhKLebxmhcSsgLLANP3ZljJ3QcAx iz4t/MtoZY3b02C19Uax43LDBGh4P00Hoew1o7SzCKAQzjknlCnH2U91Hm8rOojI QvPI27vWoy/mLXyCt7xtNG/qz0xedQM45CLmWFo2llAhgnJwuuMy/+WaJyeT7qmr 7RmUo/VWGbvUqlkxQ6qqYrcoyMFso8AQPePXJqU9aGfVKmgNezUyevxT5NjuwzRq 0EQv8QCUKQdL+ndB1C+SQeNs2yzkZ9ViW3158BIuEjvsKFvCxVgYn/xk8rboLcDJ qWwACxaOn9TVQDH2hTyFK3YtECA47dgQeSYI5WMWsh/cJ8ecqpbyOvHro2/OaBsI 2FYxqohWYjqNvTY702iRaWR48IFYyldDOgqrFf5jjtoTlZAvoUEeApPl0ILw2+El JNu8HbrQaVBFl79bU182YXOb =Bt62 -----END PGP SIGNATURE----- ``` pinheadmz's public key is [on openpgp.org](https://keys.openpgp.org/vks/v1/by-fingerprint/E61773CD6E01040E2F1BD78CE7E2984B6289C93A) </details>
jpk68 commented 2026-12-01 20:37:50 +00:00 (Migrated from github.com)
ACK 4ec95781e0c8fed7577f661bbe04967bea76365d
winterrdog (Migrated from github.com) reviewed 2026-12-01 22:50:00 +00:00
winterrdog (Migrated from github.com) left a comment

ACK 4ec95781e0. code reviewed and tested

successfully built and tested with clang++-20 on Debian, targeting x86_64

ACK 4ec95781e0c8fed7577f661bbe04967bea76365d. code reviewed and tested successfully built and tested with `clang++-20` on Debian, targeting `x86_64`
winterrdog (Migrated from github.com) commented 2026-12-01 22:49:11 +00:00

why do we need to assert on this ?

that log comes from netbase.cpp rather 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 fine

why do we need to assert on this ? that log comes from `netbase.cpp` rather 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 fine
ViniciusCestarii (Migrated from github.com) reviewed 2026-12-02 16:28:39 +00:00
ViniciusCestarii (Migrated from github.com) commented 2026-12-02 16:28:39 +00:00

I agree, but it's harmless and this is merged now, so I'd leave it as is.

I agree, but it's harmless and this is merged now, so I'd leave it as is.
fanquake commented 2026-12-02 18:17:40 +00:00 (Migrated from github.com)
Possibly related CI failure: https://github.com/bitcoin/bitcoin/actions/runs/46929464856/job/143633649485#step:11:1
pinheadmz commented 2026-12-02 20:47:39 +00:00 (Migrated from github.com)

Damn ya know what I was looking at the port = self.next_port() line in test_connect_failure_warning() and was suspicious that other tests running in parallel would conflict. Claude told me not to worry:

another test in the same run would need a port seed whose 12-port block wraps onto this test's block (seeds about 415 apart) and would need to run at the same time

I'm sorry I should have brought it up during review. Claude wants to apologize too:

● That failure is a port collision with a neighbouring test, and it comes from the headroom problem I flagged earlier — except I got the limit wrong by one. I said two more next_port() calls would trip the assert; in fact one
more call already overflows the block, and the assert doesn't catch it.
Master now has test_password_auth (from #36637), which adds an 11th next_port() call.

Damn ya know what I was looking at the `port = self.next_port()` line in `test_connect_failure_warning()` and was suspicious that other tests running in parallel would conflict. Claude told me not to worry: > another test in the same run would need a port seed whose 12-port block wraps onto this test's block (seeds about 415 apart) and would need to run at the same time I'm sorry I should have brought it up during review. Claude wants to apologize too: > ● That failure is a port collision with a neighbouring test, and it comes from the headroom problem I flagged earlier — except I got the limit wrong by one. I said two more next_port() calls would trip the assert; in fact one more call already overflows the block, and the assert doesn't catch it. > Master now has test_password_auth (from #36637), which adds an 11th next_port() call.
ViniciusCestarii commented 2026-12-02 21:02:37 +00:00 (Migrated from github.com)

Opened #37075 for fixing it

Opened #37075 for fixing it
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36759
No description provided.