diff --git a/src/net.cpp b/src/net.cpp index 73e147c1a..2aab1dfcd 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -470,12 +470,20 @@ CNode* ConnectNode(CAddress addrConnect, const char *pszDest) { bool connected = false; std::unique_ptr sock; - if (!addrConnect.IsValid()) { - return NULL; - } + // When connecting by name (pszDest is set, e.g. -connect / -addnode host:port + // or "addnode onetry"), addrConnect is an empty placeholder — the real + // target is resolved from pszDest by ConnectSocketByName() below. Only validate + // addrConnect when we are dialing it directly (pszDest == NULL); otherwise + // IsValid()/IsReachable() on the empty address abort the connection before it is + // ever attempted, which silently breaks -connect. + if (!pszDest) { + if (!addrConnect.IsValid()) { + return NULL; + } - if (!IsReachable(addrConnect)) { - return NULL; + if (!IsReachable(addrConnect)) { + return NULL; + } } if (addrConnect.GetNetwork() == NET_I2P && m_i2p_sam_session.get() != nullptr) {