This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 4d6decf40403 CAMEL-22525: Fix flaky AS2 tests with BindException
(#22095)
4d6decf40403 is described below
commit 4d6decf40403c0aa80bfc5936cb28f19869c45a9
Author: Guillaume Nodet <[email protected]>
AuthorDate: Thu Mar 19 13:07:47 2026 +0100
CAMEL-22525: Fix flaky AS2 tests with BindException (#22095)
Add SO_REUSEADDR to ServerSocket creation in AS2ServerConnection and
AS2AsyncMDNServerConnection to prevent BindException when ports are
in TIME_WAIT state during CI test runs.
Co-authored-by: Claude Opus 4.6 <[email protected]>
---
.../camel/component/as2/api/AS2AsyncMDNServerConnection.java | 7 +++++--
.../org/apache/camel/component/as2/api/AS2ServerConnection.java | 7 +++++--
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsyncMDNServerConnection.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsyncMDNServerConnection.java
index ac5be366f896..fdb5c2d4d3a2 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsyncMDNServerConnection.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2AsyncMDNServerConnection.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.as2.api;
import java.io.IOException;
import java.io.InterruptedIOException;
+import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
@@ -123,11 +124,13 @@ public class AS2AsyncMDNServerConnection {
public RequestListenerThread(int port, SSLContext sslContext) throws
IOException {
setName(REQUEST_LISTENER_THREAD_NAME_PREFIX + port);
if (sslContext == null) {
- serverSocket = new ServerSocket(port);
+ serverSocket = new ServerSocket();
} else {
SSLServerSocketFactory factory =
sslContext.getServerSocketFactory();
- serverSocket = factory.createServerSocket(port);
+ serverSocket = factory.createServerSocket();
}
+ serverSocket.setReuseAddress(true);
+ serverSocket.bind(new InetSocketAddress(port));
HttpProcessor httpProcessor = HttpProcessorBuilder.create()
.add(new ResponseContent(true))
.add(new ResponseDate())
diff --git
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
index 7a700e01121a..3093ca39a674 100644
---
a/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
+++
b/components/camel-as2/camel-as2-api/src/main/java/org/apache/camel/component/as2/api/AS2ServerConnection.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.as2.api;
import java.io.IOException;
import java.io.InterruptedIOException;
+import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
@@ -440,11 +441,13 @@ public class AS2ServerConnection {
this.service = service;
if (sslContext == null) {
- serversocket = new ServerSocket(port);
+ serversocket = new ServerSocket();
} else {
SSLServerSocketFactory factory =
sslContext.getServerSocketFactory();
- serversocket = factory.createServerSocket(port);
+ serversocket = factory.createServerSocket();
}
+ serversocket.setReuseAddress(true);
+ serversocket.bind(new InetSocketAddress(port));
}
@Override