torcontrol: log control port connection failures at debug level #36759

pull ViniciusCestarii wants to merge 3 commits into bitcoin:master from ViniciusCestarii:prevent-tor-log-spam changing 4 files +52 −11
  1. ViniciusCestarii commented at 4:36 PM on November 4, 2026: contributor

    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 move these warnings back to debug.

  2. jpk68 commented at 6:40 PM on November 4, 2026: contributor

    ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65

  3. fanquake commented at 6:48 PM on November 4, 2026: member
  4. in src/torcontrol.cpp:98 in ac6d31e7a9
      94 | @@ -95,9 +95,9 @@ bool TorControlConnection::Connect(const std::string& tor_control_center)
      95 |          return false;
      96 |      }
      97 |  
      98 | -    m_sock = ConnectDirectly(control_service.value(), /*manual_connection=*/true);
      99 | +    m_sock = ConnectDirectly(control_service.value(), /*manual_connection=*/false);
    


    pinheadmz commented at 7:03 PM on November 4, 2026:

    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 commented at 12:12 AM on November 5, 2026:

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

  5. pinheadmz commented at 7:07 PM on November 4, 2026: member

    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.

  6. ViniciusCestarii commented at 12:23 AM on November 5, 2026: contributor

    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

  7. pinheadmz approved
  8. pinheadmz commented at 8:36 PM on November 5, 2026: member

    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

    </details>

  9. DrahtBot commented at 8:36 PM on November 5, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    Stale ACK jpk68, pinheadmz, winterrdog

    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.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  10. fanquake commented at 9:05 PM on November 5, 2026: member

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

  11. sedited requested review from fjahr on Nov 5, 2026
  12. winterrdog commented at 11:15 PM on November 5, 2026: contributor

    tested ACK ac6d31e7a9320773b98934478d0e2ea3c17dfb65

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


    logs look less noisy (quite peaceful now) when i ran bitcoind in regtest

    re: #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>

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

  13. fjahr commented at 2:04 AM on November 6, 2026: contributor

    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.

  14. ViniciusCestarii commented at 12:20 PM on November 6, 2026: contributor

    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.

  15. fjahr commented at 10:12 AM on November 7, 2026: contributor

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

    Sure, go ahead!

  16. torcontrol: Warn about failed connections only if Tor control is configured 996846efe6
  17. torcontrol: Log when an active onion service is lost 9d447f8f43
  18. torcontrol: Log first failed connection at info level if tor is not configured 43774b6b85
  19. ViniciusCestarii force-pushed on Nov 7, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-07 16:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me