@@ -177,12 +177,14 @@ public HttpConnectionPool(ConnectionConfig config) {
177177 TlsProvider tls = resolveTls (config );
178178
179179 // Use the epoll backend only when the native library is available AND the resolved TLS provider
180- // supports it. The epoll path hands the provider a null-socket context whose byte channel is
181- // consumable only by engine-based providers (via SslEngineTransports); a provider that does its
182- // own socket I/O (supportsEpoll() == false) must get the NIO socket path so socket() is non-null.
183- // Note: this also routes cleartext connections on such a client through NIO, which is acceptable,
184- // since a custom TLS provider is configured for secure traffic.
185- EpollConnector epollConnector = tls .supportsEpoll ()
180+ // supports it AND the user has not supplied a custom socket factory. The epoll path hands the
181+ // provider a null-socket context whose byte channel is consumable only by engine-based providers
182+ // (via SslEngineTransports); a provider that does its own socket I/O (supportsEpoll() == false)
183+ // must get the NIO socket path so socket() is non-null. Note: this also routes cleartext
184+ // connections on such a client through NIO, which is acceptable, since a custom TLS provider is
185+ // configured for secure traffic. A custom socketFactory likewise forces the NIO path: the epoll
186+ // connector creates its own channels and would otherwise silently bypass the user's factory.
187+ EpollConnector epollConnector = tls .supportsEpoll () && config .socketFactory () == null
186188 ? EpollConnector .createIfAvailable (
187189 config .socketReceiveBufferSize (),
188190 config .socketSendBufferSize (),
0 commit comments