MongoDB: ReplicaSet with a custom SocketFactory fails every connection with UnknownURISchemeException
ReplicaSet uses Config::socketFactory, documented as "Optional socket factory for SSL/TLS connections" (ReplicaSet.h#L125-L128), by calling conn->connect(address.toString(), *factory) in both createConnection() overloads (ReplicaSet.cpp#L480, #L526) and in updateTopologyFromHello() (#L573). SocketAddress::toString() returns host:port, but Connection::connect(const std::string& uri, SocketFactory&) expects a mongodb:// URI and throws UnknownURISchemeException for any other scheme (Connection.cpp#L157-L160). Poco::URI parses 127.0.0.1:27219 with the scheme 127.0.0.1, and [::1]:27219 with the scheme [, so every connection through a factory fails before createSocket() is called.
updateTopologyFromHello() catches the exception and marks the server Unknown (ReplicaSet.cpp#L616-L621), so discovery finds no server, and the first command fails after the reconnect retries with IOException("No suitable server found in replica set"). ReplicaSet offers TLS only through a custom factory, so a replica set that requires TLS cannot be used. No test or sample sets a factory on a ReplicaSet.
With a mongodb:// prefix alone the factory would still receive secure == false: Connection::connect(uri, factory) takes that flag from the ssl/tls URI parameter, which ReplicaSet does not pass.
Observed (1.15.3, single-member replica set, mongo:8): with Config::socketFactory set to a factory that returns a plain connected StreamSocket, the ReplicaSet constructor returns, the topology is "Replica Set (no Primary)" with the server UNKNOWN and the error "Unknown URI scheme", a ping through ReplicaSetConnection throws Poco::IOException "No suitable server found in replica set" after the reconnect retries, and createSocket() is called 0 times. Without the factory, the same program finds the primary and ping succeeds.
Expected: ReplicaSet creates every connection through the configured SocketFactory, including the hello connections used for discovery and monitoring.
Affected: 1.15.0 to 1.15.3, and the poco-1.15.4 and main branches (in 1.15.0 the calls are at ReplicaSet.cpp lines 416 and 451).
Source: pocoproject/poco