From 0a7ae9524c9db69585263535e6c92d380a31caeb Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Fri, 15 Sep 2023 11:02:17 +0100 Subject: [PATCH 1/5] Add socket connection timeout --- src/core/com/cosylab/epics/caj/impl/CAConnector.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/com/cosylab/epics/caj/impl/CAConnector.java b/src/core/com/cosylab/epics/caj/impl/CAConnector.java index 892960e..223fe62 100644 --- a/src/core/com/cosylab/epics/caj/impl/CAConnector.java +++ b/src/core/com/cosylab/epics/caj/impl/CAConnector.java @@ -51,6 +51,11 @@ public class CAConnector implements Connector { */ private static final int LOCK_TIMEOUT = 20 * 1000; // 20s + /** + * Socket connect timeout (ms). + */ + private static final int SOCKET_CONNECT_TIMEOUT = 100; + /** * Map tracking failed TCP connections */ @@ -202,7 +207,9 @@ private SocketChannel tryConnect(InetSocketAddress address, int tries) try { - return SocketChannel.open(address); + SocketChannel socketChannel = SocketChannel.open(); + socketChannel.socket().connect(address, SOCKET_CONNECT_TIMEOUT); + return socketChannel; } catch (IOException ioe) { From aeb374086905264b8d90d05da744f2cbac3faa21 Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Thu, 21 Sep 2023 10:26:41 +0100 Subject: [PATCH 2/5] Make socket connection timeout configurable --- src/core/JCALibrary.properties | 1 + .../com/cosylab/epics/caj/impl/CAConnector.java | 17 +++++++++++------ src/core/gov/aps/jca/JCALibrary.properties | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core/JCALibrary.properties b/src/core/JCALibrary.properties index b75b6aa..f8d6ad8 100644 --- a/src/core/JCALibrary.properties +++ b/src/core/JCALibrary.properties @@ -11,3 +11,4 @@ com.cosylab.epics.caj.CAJContext.server_port = 5064 com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384 com.cosylab.epics.caj.CAJContext.max_search_interval = 300 com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5 +com.cosylab.epics.caj.impl.CAConnector.socket_connect_timeout = 5000 diff --git a/src/core/com/cosylab/epics/caj/impl/CAConnector.java b/src/core/com/cosylab/epics/caj/impl/CAConnector.java index 223fe62..5190e19 100644 --- a/src/core/com/cosylab/epics/caj/impl/CAConnector.java +++ b/src/core/com/cosylab/epics/caj/impl/CAConnector.java @@ -14,6 +14,8 @@ package com.cosylab.epics.caj.impl; +import gov.aps.jca.JCALibrary; + import java.io.IOException; import java.net.InetSocketAddress; import java.nio.channels.SelectionKey; @@ -29,6 +31,7 @@ import com.cosylab.epics.caj.impl.requests.VersionRequest; import com.cosylab.epics.caj.impl.sync.NamedLockPattern; + /** * Channel Access TCP connector. * @author Matej Sekoranja @@ -45,17 +48,18 @@ public class CAConnector implements Connector { * Context instance. */ private NamedLockPattern namedLocker; + + /** + * Socket connect timeout (ms). + */ + private int socketConnectTimeout = 5000; /** * Context instance. */ private static final int LOCK_TIMEOUT = 20 * 1000; // 20s - /** - * Socket connect timeout (ms). - */ - private static final int SOCKET_CONNECT_TIMEOUT = 100; - + /** * Map tracking failed TCP connections */ @@ -67,6 +71,7 @@ public class CAConnector implements Connector { public CAConnector(CAJContext context) { this.context = context; namedLocker = new NamedLockPattern(); + socketConnectTimeout = JCALibrary.getInstance().getPropertyAsInt(this.getClass().getName()+".socket_connect_timeout", socketConnectTimeout); } /** @@ -208,7 +213,7 @@ private SocketChannel tryConnect(InetSocketAddress address, int tries) try { SocketChannel socketChannel = SocketChannel.open(); - socketChannel.socket().connect(address, SOCKET_CONNECT_TIMEOUT); + socketChannel.socket().connect(address, socketConnectTimeout); return socketChannel; } catch (IOException ioe) diff --git a/src/core/gov/aps/jca/JCALibrary.properties b/src/core/gov/aps/jca/JCALibrary.properties index 5c336fd..cec54ee 100644 --- a/src/core/gov/aps/jca/JCALibrary.properties +++ b/src/core/gov/aps/jca/JCALibrary.properties @@ -13,3 +13,4 @@ com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384 com.cosylab.epics.caj.CAJContext.min_search_interval = 0.1 com.cosylab.epics.caj.CAJContext.max_search_interval = 300.0 com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5 +com.cosylab.epics.caj.impl.CAConnector.socket_connect_timeout = 5000 From db65c80b6f0909d839954973b50e55cd63c3c6b7 Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Thu, 1 Feb 2024 15:31:57 +0000 Subject: [PATCH 3/5] Remove property as not read from this file --- src/core/JCALibrary.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/JCALibrary.properties b/src/core/JCALibrary.properties index f8d6ad8..515b6a7 100644 --- a/src/core/JCALibrary.properties +++ b/src/core/JCALibrary.properties @@ -10,5 +10,4 @@ com.cosylab.epics.caj.CAJContext.repeater_port = 5065 com.cosylab.epics.caj.CAJContext.server_port = 5064 com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384 com.cosylab.epics.caj.CAJContext.max_search_interval = 300 -com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5 -com.cosylab.epics.caj.impl.CAConnector.socket_connect_timeout = 5000 +com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5 \ No newline at end of file From 7ff5014b783f0577da98bae5ab629e690a265542 Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Thu, 1 Feb 2024 15:32:14 +0000 Subject: [PATCH 4/5] Increase default socket connent timeout to match original behaviour Update timeout property to be in secs and defined as a float. --- src/core/com/cosylab/epics/caj/impl/CAConnector.java | 9 +++++---- src/core/gov/aps/jca/JCALibrary.properties | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/com/cosylab/epics/caj/impl/CAConnector.java b/src/core/com/cosylab/epics/caj/impl/CAConnector.java index 5190e19..8dd4e24 100644 --- a/src/core/com/cosylab/epics/caj/impl/CAConnector.java +++ b/src/core/com/cosylab/epics/caj/impl/CAConnector.java @@ -50,9 +50,9 @@ public class CAConnector implements Connector { private NamedLockPattern namedLocker; /** - * Socket connect timeout (ms). + * Socket connect timeout (sec). */ - private int socketConnectTimeout = 5000; + private float socketConnectTimeout = 120.0f; /** * Context instance. @@ -71,7 +71,7 @@ public class CAConnector implements Connector { public CAConnector(CAJContext context) { this.context = context; namedLocker = new NamedLockPattern(); - socketConnectTimeout = JCALibrary.getInstance().getPropertyAsInt(this.getClass().getName()+".socket_connect_timeout", socketConnectTimeout); + socketConnectTimeout = JCALibrary.getInstance().getPropertyAsFloat(this.getClass().getName()+".socket_connect_timeout", socketConnectTimeout); } /** @@ -213,7 +213,8 @@ private SocketChannel tryConnect(InetSocketAddress address, int tries) try { SocketChannel socketChannel = SocketChannel.open(); - socketChannel.socket().connect(address, socketConnectTimeout); + int socketConnectTimeoutMs = (int) (socketConnectTimeout * 1000); + socketChannel.socket().connect(address, socketConnectTimeoutMs); return socketChannel; } catch (IOException ioe) diff --git a/src/core/gov/aps/jca/JCALibrary.properties b/src/core/gov/aps/jca/JCALibrary.properties index cec54ee..e7b519e 100644 --- a/src/core/gov/aps/jca/JCALibrary.properties +++ b/src/core/gov/aps/jca/JCALibrary.properties @@ -13,4 +13,4 @@ com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384 com.cosylab.epics.caj.CAJContext.min_search_interval = 0.1 com.cosylab.epics.caj.CAJContext.max_search_interval = 300.0 com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5 -com.cosylab.epics.caj.impl.CAConnector.socket_connect_timeout = 5000 +com.cosylab.epics.caj.impl.CAConnector.socket_connect_timeout = 120.0 From b4ba49bf4360cd10e7da2be354240e7682c1407c Mon Sep 17 00:00:00 2001 From: Rebecca Williams Date: Thu, 1 Feb 2024 15:38:32 +0000 Subject: [PATCH 5/5] Add newline to end of file --- src/core/JCALibrary.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/JCALibrary.properties b/src/core/JCALibrary.properties index 515b6a7..b75b6aa 100644 --- a/src/core/JCALibrary.properties +++ b/src/core/JCALibrary.properties @@ -10,4 +10,4 @@ com.cosylab.epics.caj.CAJContext.repeater_port = 5065 com.cosylab.epics.caj.CAJContext.server_port = 5064 com.cosylab.epics.caj.CAJContext.max_array_bytes = 16384 com.cosylab.epics.caj.CAJContext.max_search_interval = 300 -com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5 \ No newline at end of file +com.cosylab.epics.caj.impl.reactor.lf.LeaderFollowersThreadPool.thread_pool_size = 5