Repository navigation
Description
I'm using the --torcontrol feature to automatically create a tor hidden service. From the logs, the control connection is established and authenticated, and the hidden service added, and correct onionv3 address assigned. However:
- There are no incoming P2P connections via Tor (they fail to connect, see below).
- If I try to connect manually, it fails (General SOCKS server failure)
Here is an excerpt of the failure on the tor side:
tor_1 | May 09 14:44:44.000 [debug] connection_exit_begin_conn(): Creating new exit connection.
tor_1 | May 09 14:44:44.000 [debug] circuit_get_by_circid_channel_impl(): circuit_get_by_circid_channel_impl() returning circuit 0x7f5274f0c200 for circ_id 3666618028, channel ID 5 (0x7f527505dda0)
tor_1 | May 09 14:44:44.000 [debug] handle_hs_exit_conn(): Connecting the hidden service rendezvous circuit to the service destination.
tor_1 | May 09 14:44:44.000 [debug] circuit_get_by_circid_channel_impl(): circuit_get_by_circid_channel_impl() returning circuit 0x7f5274f0c200 for circ_id 3666618028, channel ID 5 (0x7f527505dda0)
tor_1 | May 09 14:44:44.000 [debug] connection_exit_connect(): about to try connecting
tor_1 | May 09 14:44:44.000 [debug] connection_connect(): Connecting to "(rendezvous)":38334.
tor_1 | May 09 14:44:44.000 [debug] connection_connect_sockaddr(): Connection to socket in progress (sock 12).
tor_1 | May 09 14:44:44.000 [debug] connection_add_impl(): new conn type Exit, socket 12, address (rendezvous), n_conns 14.
tor_1 | May 09 14:44:44.000 [debug] connection_or_process_cells_from_inbuf(): 15: starting, inbuf_datalen 0 (0 pending in tls object).
tor_1 | May 09 14:44:44.000 [debug] conn_write_callback(): socket 12 wants to write.
tor_1 | May 09 14:44:44.000 [info] connection_handle_write_impl(): in-progress connect failed. Removing. (Connection refused)
tor_1 | May 09 14:44:44.000 [debug] connection_edge_end(): Sending end on conn (fd 12).
I specifically wonder why address "(rendezvous)", and why address 38334? Both are wrong.
I used nc -v -x 127.0.0.1:9050 sxvxellncmexkds7h3kjy62vl67xwvrccqiigrdybbc4jutjf6amtuad.onion 38333 to connect to the hidden service, which yields nc: connection failed, SOCKSv5 error: General SOCKS server failure.
@jonatack used bitcoin-cli addnode sxvxellncmexkds7h3kjy62vl67xwvrccqiigrdybbc4jutjf6amtuad.onion onetry on his bitcoin node to the same error message.
My bitcoind options are (env vars are resolved by docker-compose):
-signet=1
-disablewallet=1
-txindex=1
-blockfilterindex=basic
-peerbloomfilters=1
-peerblockfilters=1
-logtimestamps=0
-maxconnections=32
-listen=1
-discover=1
-dnsseed=0
-onlynet=i2p
-i2psam=i2pd:${I2PD_PORT}
-i2pacceptincoming=1
-onlynet=onion
-listenonion=1
-onion=tor:${TOR_SOCKS_PORT}
-torcontrol=tor:${TOR_CONTROL_PORT}
-torpassword=xxx
-rpcbind=0.0.0.0:${BITCOIND_RPC_PORT}
-rpcallowip=0.0.0.0/0
-rpcauth=xxx
-rpcthreads=2
-par=2
-debug=tor
My torrc is pretty default, but I'm using these command line options on top:
ControlPort 0.0.0.0:9051 HashedControlPassword xxx Log "debug stdout" SafeLogging 0
I'm attaching full logs of bitcoind and tor.
log-bitcoind.txt
log-tor.txt.gz
I would expect bitcoind to automatically configure the hidden service for me (as documented in tor.md) and listen for incoming tor connections. As a side note, I've migrated from the configuration variant that manages the hidden service within tor.
System information
- Bitcoin Core 23.0 within Docker version 20.10.12 under Ubuntu 22.04 LTS
- Tor 0.4.7.7 within Docker version 20.10.12 under Ubuntu 22.04 LTS
- All on an Intel Celeron home server.
Activity
[-]Hiden service created by `--torcontrol` does not accept connections (General SOCKS server failure)[/-][+]Hidden service created by `--torcontrol` does not accept connections (General SOCKS server failure)[/+]schildbach commentedon Nov 10, 2022
I retested this using 24.0rc5, and I also set up a second bitcoind instance just for testing my hidden service. Similar setup, but I use
to specifically only connect to my hidden server (address redacted). However, all I get in the log of the connecting bitcoind is:
Note that if I configure a hidden service manually (in the tor container), I can connect. So my test setup seems to be fine.
It would be great if I could somehow see in the logs what bitcoind tells tor via the control port. For example, does it perhaps tell to connect to localhost rather than bitcoind? Does such a tracelog exist?
schildbach commentedon Nov 11, 2022
I'm now pretty confident that the hidden service configuration of bitcoind via control port is broken in the following way:
If you bind the port for incoming onion connections via wildcard, like this
it uses that wildcard address as a target address for the hidden service. Which will fail, because a wildcard has a different meaning to the container that has Tor. The result is zero incoming connections via hidden service, and the above errors on the client side of the hidden service.
vasild commentedon Nov 11, 2022
The default for signet is
-bind=127.0.0.1:38334=onion. From your attachedlog-bitcoind.txt:Then
bitcoindis telling the tor daemon to redirect connections destined to the.onionaddress to127.0.0.1:38334. This obviously does not work when Tor is running on a different machine thanbitcoind. You need to modify the default to something like-bind=a.b.c.d:38334=onionsuch thatbitcoindcan bind toa.b.c.dand the tor daemon can connect to it.[::]fulfills the first but not the second :(Is it not possible to have the docker-assigned IP address of the machine in an environment variable, like e.g.
${TOR_SOCKS_PORT}from above?schildbach commentedon Nov 11, 2022
Sorry for the signet/mainnet mismatch between my May and current configurations. Btw. the hidden service address from May also doesn't exist any more, I think.
It probably shouldn't do that and instead print a message to the log? And, like I suggested in the other issue, maybe a configuration option for what address to use in this case would make sense?
Afaik no. Docker recommends using hostnames.
vasild commentedon Nov 11, 2022
Why? It works well in the default case when tor is on the same machine and
-bind=127.0.0.1:8334=onionand-torcontrol=127.0.0.1:9051(these are the default values). You have changed-torcontrol, but not-bind=...=onion. If you change the latter, then it will work too.The only problem is that you want to use a hostname instead of an IP address for
-bind, right?schildbach commentedon Nov 11, 2022
What I meant is it should probably not silently convert
[::]to127.0.0.1. Yes, if you bind to127.0.0.1then it's expected to use127.0.0.1for the hidden service target. Of course running bitcoind and tor in the same container is not really recommended.An elegant way to support the container isolated case would be
or
"hiddenservicetarget" being a new option that would separate the bind address from the target address. If it exists, bitcoind would not try to derive the target address from the onion bind address and instead use the value of the option.
I think one of these two ways should be considered in order to support container isolation.
vasild commentedon Nov 11, 2022
Yes, probably it makes sense to print something like "tor control returned an invalid address for the socks5 proxy: [::]:9050, falling back to the default 127.0.0.1:9050`.
I agree.
kosuodhmwa commentedon Mar 28, 2024
comassky commentedon Oct 22, 2025
Hi, same issue here with 29.2
When i use an other node to test connect :
vasild commentedon Sep 10, 2026
That will make
bitcoindbind on all addresses. If the machine has a public IP address, then anybody who connects to it on port8334will trick yourbitcoindthat it is an incoming connection over Tor, whereas it will not be. Does not sound too dangerous, but still better avoid that. You never know how creative some attacker may be.Then another problem with
bind=0.0.0.0:8334=onionis thatbitcoindwill tell the Tor daemon: "whenever a connection comes tomyaddress.onion:8333forward it to0.0.0.0:8334". Then the Tor daemon may try to connect to0.0.0.0:8334but that will fail, can't connect to0.0.0.0!Should we forbid
bind=0.0.0.0:port=onionaltogether and error at startup? Maybe, but there are scenarios where 1. and 2. are not a problem - for example, if the machine has no public addresses, or has a firewall, then no outsiders can connect to its public IP address on port8334, so 1. is no issue. 2. might not be a problem either if the hidden service is configured statically intorrc, for example:and then
bitcoindruns on the machine with address10.0.0.5and binds on0.0.0.0(= all addresses) and so Tor can connect to it viaHiddenServicePort 8333 10.0.0.5:8334.One thing that cannot work for sure is
-bind=0.0.0.0:port=onion -listenonion=1wherebitcoindautomatically creates the hidden service - then it does not know which address to tell Tor to connect to, it will tell it to connect to0.0.0.0and that will not work. I guess that is safe for forbid/error at startup.schildbach commentedon Sep 10, 2026
ad 1. In Docker environments, it's very common to bind to
0.0.0.0and/or[::], because you don't know your IPs beforehand – it's assigned at container creation time. That, combined with the common practise to separate services into different containers – in this case bitcoind and tor.schildbach commentedon Sep 10, 2026
ad 2. Yes, that is the root cause of this issue. My suggestion is to (optionally) separate the bind address from the "talkback" address that is told to the tor daemon. Ideally, make it possible to tell tor a hostname that it can resolve, or resolve it on the bitcoind side and tell the resolved IP.
vasild commentedon Oct 6, 2026
Using hostnames seems messy to me. It opens a lot of new possibilities where things can fail or go in unexpected ways. I am not a docker expert, but I think that it is possible to tell docker to use static pre-configured addresses or let it assign random ones and then query the actual address and set it in
bitcoin.conf(e.g.sed s/MYADDR/$myaddr/ < bitcoin.conf.template > bitcoin.conf).#36170 aims to prevent startup if
-bind=0.0.0.0:port=onion -listenonion=1is used.schildbach commentedon Oct 6, 2026
Forcing the user to pipe the config through a startup script seems messy to me. Hostname resolution is the standard way to deal with dynamic IPs.
You can tell Docker to use a certain address range for a network, but you cannot assign a specific address within that network to a container.