From 5460739293ccd8e89adc9edb4653b4de28b09897 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Tue, 11 Apr 2023 19:28:43 -0700 Subject: Handle closed connections --- src/main/java/org/traccar/forward/NetworkForwarder.java | 11 +++++++++++ .../java/org/traccar/handler/NetworkForwarderHandler.java | 8 ++++++++ 2 files changed, 19 insertions(+) (limited to 'src/main/java/org/traccar') diff --git a/src/main/java/org/traccar/forward/NetworkForwarder.java b/src/main/java/org/traccar/forward/NetworkForwarder.java index 6abf2b7ba..0915aaa27 100644 --- a/src/main/java/org/traccar/forward/NetworkForwarder.java +++ b/src/main/java/org/traccar/forward/NetworkForwarder.java @@ -63,4 +63,15 @@ public class NetworkForwarder { } } + public void disconnect(InetSocketAddress source) { + Socket connectionTcp = connectionsTcp.remove(source); + if (connectionTcp != null) { + try { + connectionTcp.close(); + } catch (IOException e) { + LOGGER.warn("Connection close error", e); + } + } + } + } diff --git a/src/main/java/org/traccar/handler/NetworkForwarderHandler.java b/src/main/java/org/traccar/handler/NetworkForwarderHandler.java index a3792a3e5..2c586c973 100644 --- a/src/main/java/org/traccar/handler/NetworkForwarderHandler.java +++ b/src/main/java/org/traccar/handler/NetworkForwarderHandler.java @@ -61,4 +61,12 @@ public class NetworkForwarderHandler extends ChannelInboundHandlerAdapter { super.channelRead(ctx, msg); } + @Override + public void channelInactive(ChannelHandlerContext ctx) throws Exception { + if (!(ctx.channel() instanceof DatagramChannel)) { + networkForwarder.disconnect((InetSocketAddress) ctx.channel().remoteAddress()); + } + super.channelInactive(ctx); + } + } -- cgit v1.2.3