pooler / cpuminer

CPU miner for Litecoin and Bitcoin
https://bitcointalk.org/index.php?topic=55038.0
Other
2.79k stars 1.21k forks source link

IPv4+IPv6 pool domain failed to connect when IPv6 is not available #159

Closed felixonmars closed 4 years ago

felixonmars commented 6 years ago

I am trying to connect to a pool server, the domain resolves to both IPv4 and IPv6. However it is not possible to connect if I don't have IPv6 locally. The -P log looks like the following:

* Rebuilt URL to: http://<mydomain>/
*   Trying <ipv4-address>...
* TCP_NODELAY set
*   Trying <ipv6-address>...
* TCP_NODELAY set
* Immediate connect fail for <ipv6-address>: Network is unreachable
* Connected to <mydomain> (<ipv4-address>) port <myport> (#0)
* Connection #0 to host <mydomain> left intact
[2018-01-27 07:03:51] > {"id": 1, "method": "mining.subscribe", "params": ["cpuminer/2.5.0"]}
[2018-01-27 07:03:51] stratum_subscribe send failed
[2018-01-27 07:03:51] ...retry after 30 seconds

However it connects and runs successfully with either the IPv4 address directly or a domain that resolves only to the IPv4 address.

pooler commented 4 years ago

Sorry for the very late reply.

I tried reproducing this but I couldn't. If you can still reproduce it, what version of libcurl and what DNS resolver are you using?

pooler commented 4 years ago

I managed to reproduce something similar to what you reported. In both cases, the problem seems to be that cpuminer always ends up using the socket that was created last. This is an issue, for instance, if curl attempts to connect to both IPv6 and IPv4 addresses simultaneously, as happens with the "Happy Eyeballs" algorithm, and the latter attempt fails.

I believe this can be fixed by simply obtaining the socket via CURLINFO_ACTIVESOCKET, which is available since curl 7.45.0.

felixonmars commented 4 years ago

Many thanks!