From d3699cf8b4d34f4e167ef2d404209cfac0b7228f Mon Sep 17 00:00:00 2001 From: He-Pin Date: Tue, 30 Sep 2025 22:58:03 +0800 Subject: [PATCH] chore: Set reuseAddr/port in temporaryServerAddresses --- .../main/scala/org/apache/pekko/testkit/SocketUtil.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/testkit/src/main/scala/org/apache/pekko/testkit/SocketUtil.scala b/testkit/src/main/scala/org/apache/pekko/testkit/SocketUtil.scala index 8acf66ad5b4..7dd873c0b8a 100644 --- a/testkit/src/main/scala/org/apache/pekko/testkit/SocketUtil.scala +++ b/testkit/src/main/scala/org/apache/pekko/testkit/SocketUtil.scala @@ -13,10 +13,9 @@ package org.apache.pekko.testkit -import java.net.{ DatagramSocket, InetSocketAddress, NetworkInterface, StandardProtocolFamily } +import java.net.{ DatagramSocket, InetSocketAddress, NetworkInterface, StandardProtocolFamily, StandardSocketOptions } import java.nio.channels.DatagramChannel import java.nio.channels.ServerSocketChannel - import scala.collection.immutable import scala.util.Random import scala.util.control.NonFatal @@ -104,7 +103,10 @@ object SocketUtil { ds.bind(addr) (ds, new InetSocketAddress(address, ds.getLocalPort)) } else { - val ss = ServerSocketChannel.open().socket() + val serverSocketChannel = ServerSocketChannel.open + serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEADDR, java.lang.Boolean.TRUE) + serverSocketChannel.setOption(StandardSocketOptions.SO_REUSEPORT, java.lang.Boolean.TRUE) + val ss = serverSocketChannel.socket() ss.bind(addr) (ss, new InetSocketAddress(address, ss.getLocalPort)) }