This is an automated email from the ASF dual-hosted git repository.

hepin pushed a commit to branch flasky
in repository https://gitbox.apache.org/repos/asf/pekko.git

commit d3699cf8b4d34f4e167ef2d404209cfac0b7228f
Author: He-Pin <[email protected]>
AuthorDate: Tue Sep 30 22:58:03 2025 +0800

    chore: Set reuseAddr/port in temporaryServerAddresses
---
 testkit/src/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 8acf66ad5b..7dd873c0b8 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))
           }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to