You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by rs...@apache.org on 2025/10/10 13:38:49 UTC

(httpcomponents-client) branch master updated: Avoid setting TCP socket options on Unix domain sockets

This is an automated email from the ASF dual-hosted git repository.

rschmitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git


The following commit(s) were added to refs/heads/master by this push:
     new a8a04b146 Avoid setting TCP socket options on Unix domain sockets
a8a04b146 is described below

commit a8a04b146df2fde55cd8b9b5d80d801ec8e49f76
Author: Ryan Schmitt <rs...@apache.org>
AuthorDate: Thu Oct 9 21:32:00 2025 -0700

    Avoid setting TCP socket options on Unix domain sockets
---
 .../io/DefaultHttpClientConnectionOperator.java    | 37 +++++++++++++---------
 1 file changed, 22 insertions(+), 15 deletions(-)

diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
index 695edae54..d1e31cddd 100644
--- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
+++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/io/DefaultHttpClientConnectionOperator.java
@@ -215,7 +215,7 @@ public void connect(
                     socket.bind(localAddress);
                 }
                 conn.bind(socket);
-                configureSocket(socket, socketConfig);
+                configureSocket(socket, socketConfig, true);
                 socket.connect(remoteAddress, TimeValue.isPositive(connectTimeout) ? connectTimeout.toMillisecondsIntBound() : 0);
                 conn.bind(socket);
                 onAfterSocketConnect(context, endpointHost);
@@ -288,7 +288,7 @@ private void connectToUnixDomainSocket(
             final Socket socket = unixDomainSocketFactory.connectSocket(newSocket, unixDomainSocket,
                 connectTimeout);
             conn.bind(socket);
-            configureSocket(socket, socketConfig);
+            configureSocket(socket, socketConfig, false);
             onAfterSocketConnect(context, endpointHost);
             if (LOG.isDebugEnabled()) {
                 LOG.debug("{} {} connected to {}", ConnPoolSupport.getId(conn), endpointHost, unixDomainSocket);
@@ -312,14 +312,15 @@ private void connectToUnixDomainSocket(
     }
 
     @SuppressWarnings("Since15")
-    private static void configureSocket(final Socket socket, final SocketConfig socketConfig) throws IOException {
+    private static void configureSocket(
+        final Socket socket,
+        final SocketConfig socketConfig,
+        final boolean isTcp
+    ) throws IOException {
         final Timeout socketTimeout = socketConfig.getSoTimeout();
         if (socketTimeout != null) {
             socket.setSoTimeout(socketTimeout.toMillisecondsIntBound());
         }
-        socket.setReuseAddress(socketConfig.isSoReuseAddress());
-        socket.setTcpNoDelay(socketConfig.isTcpNoDelay());
-        socket.setKeepAlive(socketConfig.isSoKeepAlive());
         if (socketConfig.getRcvBufSize() > 0) {
             socket.setReceiveBufferSize(socketConfig.getRcvBufSize());
         }
@@ -331,15 +332,21 @@ private static void configureSocket(final Socket socket, final SocketConfig sock
         if (linger >= 0) {
             socket.setSoLinger(true, linger);
         }
-        if (SUPPORTS_KEEPALIVE_OPTIONS) {
-            if (socketConfig.getTcpKeepIdle() > 0) {
-                Sockets.setOption(socket, ExtendedSocketOptions.TCP_KEEPIDLE, socketConfig.getTcpKeepIdle());
-            }
-            if (socketConfig.getTcpKeepInterval() > 0) {
-                Sockets.setOption(socket, ExtendedSocketOptions.TCP_KEEPINTERVAL, socketConfig.getTcpKeepInterval());
-            }
-            if (socketConfig.getTcpKeepCount() > 0) {
-                Sockets.setOption(socket, ExtendedSocketOptions.TCP_KEEPCOUNT, socketConfig.getTcpKeepCount());
+        if (isTcp) {
+            socket.setReuseAddress(socketConfig.isSoReuseAddress());
+            socket.setTcpNoDelay(socketConfig.isTcpNoDelay());
+            socket.setKeepAlive(socketConfig.isSoKeepAlive());
+            if (SUPPORTS_KEEPALIVE_OPTIONS) {
+                if (socketConfig.getTcpKeepIdle() > 0) {
+                    Sockets.setOption(socket, ExtendedSocketOptions.TCP_KEEPIDLE, socketConfig.getTcpKeepIdle());
+                }
+                if (socketConfig.getTcpKeepInterval() > 0) {
+                    Sockets.setOption(socket, ExtendedSocketOptions.TCP_KEEPINTERVAL,
+                        socketConfig.getTcpKeepInterval());
+                }
+                if (socketConfig.getTcpKeepCount() > 0) {
+                    Sockets.setOption(socket, ExtendedSocketOptions.TCP_KEEPCOUNT, socketConfig.getTcpKeepCount());
+                }
             }
         }
     }