From 2599e46f46d28c7e8de7e6698381a9def527950f Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Tue, 1 Apr 2025 10:38:11 -0400 Subject: [PATCH 1/3] step1 for fixing tcp connections delays, based on the discussion #3338 --- .../java/org/epics/pva/common/SecureSockets.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java b/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java index 7179d677ca..e3dff1d7b6 100644 --- a/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java +++ b/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java @@ -160,12 +160,18 @@ public static ServerSocket createServerSocket(final InetSocketAddress address, f public static Socket createClientSocket(final InetSocketAddress address, final boolean tls) throws Exception { initialize(); - if (! tls) - return new Socket(address.getAddress(), address.getPort()); + int connection_timeout = Math.max(1, PVASettings.EPICS_PVA_CONN_TMO) * 1000; // Use EPICS_PVA_CONN_TMO for socket connection timeout, but at least 1 second + + if (!tls) { + Socket socket = new Socket(); + socket.connect(address, connection_timeout); + return socket; + } if (tls_client_sockets == null) throw new Exception("TLS is not supported. Configure EPICS_PVA_TLS_KEYCHAIN"); - final SSLSocket socket = (SSLSocket) tls_client_sockets.createSocket(address.getAddress(), address.getPort()); + final SSLSocket socket = (SSLSocket) tls_client_sockets.createSocket(); + socket.connect(address, connection_timeout); socket.setEnabledProtocols(PROTOCOLS); // Handshake starts when first writing, but that might delay SSL errors, so force handshake before we use the socket socket.startHandshake(); From 181442d2433d7997e5b856bf1c50f319c647be57 Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Tue, 1 Apr 2025 11:10:52 -0400 Subject: [PATCH 2/3] creating a preference for defining socket connection timeout --- .../src/main/java/org/phoebus/pv/pva/PVA_Preferences.java | 1 + .../pv-pva/src/main/resources/pv_pva_preferences.properties | 3 +++ core/pva/src/main/java/org/epics/pva/PVASettings.java | 6 ++++++ .../src/main/java/org/epics/pva/common/SecureSockets.java | 2 +- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/pv-pva/src/main/java/org/phoebus/pv/pva/PVA_Preferences.java b/core/pv-pva/src/main/java/org/phoebus/pv/pva/PVA_Preferences.java index a0c6f28412..3a68de5c42 100644 --- a/core/pv-pva/src/main/java/org/phoebus/pv/pva/PVA_Preferences.java +++ b/core/pv-pva/src/main/java/org/phoebus/pv/pva/PVA_Preferences.java @@ -65,6 +65,7 @@ public void installPreferences() throws Exception "epics_pva_server_port", "epics_pva_broadcast_port", "epics_pva_conn_tmo", + "epics_pva_tcp_socket_tmo", "epics_pva_max_array_formatting", "epics_pva_send_buffer_size" }) diff --git a/core/pv-pva/src/main/resources/pv_pva_preferences.properties b/core/pv-pva/src/main/resources/pv_pva_preferences.properties index 2be095c556..5a62ac2f95 100644 --- a/core/pv-pva/src/main/resources/pv_pva_preferences.properties +++ b/core/pv-pva/src/main/resources/pv_pva_preferences.properties @@ -37,6 +37,9 @@ epics_pva_server_port # Connection timeout in seconds epics_pva_conn_tmo +# TCP socket creation timeout in seconds +epics_pva_tcp_socket_tmo + # Maximum number of array elements shown when printing data epics_pva_max_array_formatting diff --git a/core/pva/src/main/java/org/epics/pva/PVASettings.java b/core/pva/src/main/java/org/epics/pva/PVASettings.java index 1876e3170c..eda3b03bc4 100644 --- a/core/pva/src/main/java/org/epics/pva/PVASettings.java +++ b/core/pva/src/main/java/org/epics/pva/PVASettings.java @@ -212,6 +212,12 @@ public class PVASettings */ public static int EPICS_PVA_CONN_TMO = 30; + /** Socket timeout for TCP connections + * + * TCP socket creation timeout in seconds + */ + public static int EPICS_PVA_TCP_SOCKET_TMO = 30; + /** Maximum number of array elements shown when printing data */ public static int EPICS_PVA_MAX_ARRAY_FORMATTING = 256; diff --git a/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java b/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java index e3dff1d7b6..1f5ee8f14e 100644 --- a/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java +++ b/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java @@ -160,7 +160,7 @@ public static ServerSocket createServerSocket(final InetSocketAddress address, f public static Socket createClientSocket(final InetSocketAddress address, final boolean tls) throws Exception { initialize(); - int connection_timeout = Math.max(1, PVASettings.EPICS_PVA_CONN_TMO) * 1000; // Use EPICS_PVA_CONN_TMO for socket connection timeout, but at least 1 second + int connection_timeout = Math.max(1, PVASettings.EPICS_PVA_TCP_SOCKET_TMO) * 1000; // Use EPICS_PVA_CONN_TMO for socket connection timeout, but at least 1 second if (!tls) { Socket socket = new Socket(); From 0969d1ffdc6e7f876ab108d9ae996000a1b3f00d Mon Sep 17 00:00:00 2001 From: Kunal Shroff Date: Wed, 2 Apr 2025 11:34:55 -0400 Subject: [PATCH 3/3] fix mapping of preference to settings for socket connection timeout --- core/pva/src/main/java/org/epics/pva/PVASettings.java | 3 ++- core/pva/src/main/java/org/epics/pva/common/SecureSockets.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/PVASettings.java b/core/pva/src/main/java/org/epics/pva/PVASettings.java index eda3b03bc4..0d60a3fa2e 100644 --- a/core/pva/src/main/java/org/epics/pva/PVASettings.java +++ b/core/pva/src/main/java/org/epics/pva/PVASettings.java @@ -216,7 +216,7 @@ public class PVASettings * * TCP socket creation timeout in seconds */ - public static int EPICS_PVA_TCP_SOCKET_TMO = 30; + public static int EPICS_PVA_TCP_SOCKET_TMO = 5; /** Maximum number of array elements shown when printing data */ public static int EPICS_PVA_MAX_ARRAY_FORMATTING = 256; @@ -269,6 +269,7 @@ public class PVASettings EPICS_PVA_BROADCAST_PORT = get("EPICS_PVA_BROADCAST_PORT", EPICS_PVA_BROADCAST_PORT); EPICS_PVAS_BROADCAST_PORT = get("EPICS_PVAS_BROADCAST_PORT", EPICS_PVAS_BROADCAST_PORT); EPICS_PVA_CONN_TMO = get("EPICS_PVA_CONN_TMO", EPICS_PVA_CONN_TMO); + EPICS_PVA_TCP_SOCKET_TMO = get("EPICS_PVA_TCP_SOCKET_TMO", EPICS_PVA_TCP_SOCKET_TMO); EPICS_PVA_MAX_ARRAY_FORMATTING = get("EPICS_PVA_MAX_ARRAY_FORMATTING", EPICS_PVA_MAX_ARRAY_FORMATTING); EPICS_PVAS_TLS_KEYCHAIN = get("EPICS_PVAS_TLS_KEYCHAIN", EPICS_PVAS_TLS_KEYCHAIN); EPICS_PVAS_TLS_OPTIONS = get("EPICS_PVAS_TLS_OPTIONS", EPICS_PVAS_TLS_OPTIONS); diff --git a/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java b/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java index 1f5ee8f14e..65959f2667 100644 --- a/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java +++ b/core/pva/src/main/java/org/epics/pva/common/SecureSockets.java @@ -160,7 +160,7 @@ public static ServerSocket createServerSocket(final InetSocketAddress address, f public static Socket createClientSocket(final InetSocketAddress address, final boolean tls) throws Exception { initialize(); - int connection_timeout = Math.max(1, PVASettings.EPICS_PVA_TCP_SOCKET_TMO) * 1000; // Use EPICS_PVA_CONN_TMO for socket connection timeout, but at least 1 second + int connection_timeout = Math.max(1, PVASettings.EPICS_PVA_TCP_SOCKET_TMO) * 1000; // Use EPICS_PVA_TCP_SOCKET_TMO for socket connection timeout, but at least 1 second if (!tls) { Socket socket = new Socket();