From 0108993215a48224c6d91314b4ca1b2fa168d8e8 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Mon, 24 Mar 2025 14:20:16 +0100 Subject: [PATCH] CSSTUDIO-3113 Accept TCP connections on a separate thread. --- .../java/org/epics/pva/client/PVAClient.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/core/pva/src/main/java/org/epics/pva/client/PVAClient.java b/core/pva/src/main/java/org/epics/pva/client/PVAClient.java index 4f22ad140a..f1d14756d9 100644 --- a/core/pva/src/main/java/org/epics/pva/client/PVAClient.java +++ b/core/pva/src/main/java/org/epics/pva/client/PVAClient.java @@ -250,32 +250,35 @@ void handleSearchResponse(final int channel_id, final InetSocketAddress server, channel.setState(ClientChannelState.FOUND); logger.log(Level.FINE, () -> "Reply for " + channel + " from " + (tls ? "TLS " : "TCP ") + server + " " + guid); - final ClientTCPHandler tcp = tcp_handlers.computeIfAbsent(server, addr -> - { - try + Thread thread = new Thread(() -> { + final ClientTCPHandler tcp = tcp_handlers.computeIfAbsent(server, addr -> { - return new ClientTCPHandler(this, addr, guid, tls); + try + { + return new ClientTCPHandler(this, addr, guid, tls); + } + catch (Exception ex) + { + logger.log(Level.WARNING, "Cannot connect to TCP " + addr, ex); + } + return null; + }); + // In case of connection errors, tcp will be null + if (tcp == null) + { // Cannot connect to server on provided port? Likely a server or firewall problem. + // On the next search, that same server might reply and then we fail the same way on connect. + // Still, no way around re-registering the search so we succeed once the server is fixed. + search.register(channel, false /* not "now" but eventually */); } - catch (Exception ex) + else { - logger.log(Level.WARNING, "Cannot connect to TCP " + addr, ex); + if (tcp.updateGuid(guid)) + logger.log(Level.FINE, "Search-only TCP handler received GUID, now " + tcp); + + channel.registerWithServer(tcp); } - return null; }); - // In case of connection errors, tcp will be null - if (tcp == null) - { // Cannot connect to server on provided port? Likely a server or firewall problem. - // On the next search, that same server might reply and then we fail the same way on connect. - // Still, no way around re-registering the search so we succeed once the server is fixed. - search.register(channel, false /* not "now" but eventually */); - } - else - { - if (tcp.updateGuid(guid)) - logger.log(Level.FINE, "Search-only TCP handler received GUID, now " + tcp); - - channel.registerWithServer(tcp); - } + thread.start(); } /** Called by {@link ClientTCPHandler} when connection is lost or closed because unused