From 0f402ca2e655a50ef749edd867d727f3f1d1ec20 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 5 Jan 2024 15:53:37 -0500 Subject: [PATCH] GH-8852: Fix TcpNetServerConnectionFactory.run loop Fixes: #8852 The `while (true) {` causes the thread to be blocked forever. The `stop()` waits on the `if (!executorService.awaitTermination(10, TimeUnit.SECONDS)) {` the whole time * Fix with the `while (isActive()) {` * Remove the `ConnectionFactoryTests.testEarlyCloseNet()` since we cannot reach expectations because of race condition between `start()` and `stop()` **Cherry-pick to `6.2.x` & `6.1.x`** (cherry picked from commit 0b60dfc9d13c43e3d592f05678a04c1071ea1d45) --- .../ip/tcp/connection/TcpNetServerConnectionFactory.java | 4 ++-- .../ip/tcp/connection/ConnectionFactoryTests.java | 8 +------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java index e6b44ef9afe..38109990611 100644 --- a/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java +++ b/spring-integration-ip/src/main/java/org/springframework/integration/ip/tcp/connection/TcpNetServerConnectionFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -116,7 +116,7 @@ public void run() { } try { setupServerSocket(); - while (true) { + while (isActive()) { acceptConnectionAndExecute(); } } diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java index b94a5c71f83..c298fcf994d 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -222,12 +222,6 @@ public void testObtainConnectionIds(AbstractServerConnectionFactory serverFactor scheduler.shutdown(); } - @Test - public void testEarlyCloseNet() throws Exception { - AbstractServerConnectionFactory factory = new TcpNetServerConnectionFactory(0); - testEarlyClose(factory, "serverSocket", " stopped before accept"); - } - @Test public void testEarlyCloseNio() throws Exception { AbstractServerConnectionFactory factory = new TcpNioServerConnectionFactory(0);