You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "He-Pin (via GitHub)" <gi...@apache.org> on 2026/10/24 16:44:19 UTC

[PR] Answer GetSockAddr asynchronously in the testconductor Controller [pekko]

He-Pin opened a new pull request, #3707:
URL: https://github.com/apache/pekko/pull/3707

   ### Motivation
   `Controller` answers `GetSockAddr` by calling the Netty bind future's blocking `sync()` inside its message handler. Since the same actor also hosts the `BarrierCoordinator`, a slow bind stalls every barrier in the suite, and a bind failure (e.g. the fixed conductor port 4711 being taken) is rethrown out of `receive` instead of being reported to the requester — the other nodes then time out on queries or barriers far from the cause.
   
   ### Modification
   - Register a listener on `connection.channelFuture` that reports `SockAddrBound(addr)` / `SockAddrBindFailed(cause)` to the Controller as messages.
   - `GetSockAddr` replies from the resolved address, or queues the requester until the bind completes.
   - A failed bind is logged, reported to pending requesters as `Status.Failure` (so `Conductor.sockAddr`'s Future fails and `startController` fails immediately and legibly), and stops the Controller.
   - `ControllerSpec`: new cases for the actually bound address (port 0) and for an unbindable port.
   
   Scoped to the blocking-`sync()` part of #3693; the fixed default port / port-0 publication across JVMs is a runner-coordination change left for separate discussion.
   
   ### Result
   The Controller thread never blocks on the bind future, and a conductor bind failure surfaces as a failed Future at the caller instead of an exception thrown out of a message handler.
   
   ### Tests
   - `sbt "remote-tests / Test / testOnly org.apache.pekko.remote.testconductor.ControllerSpec"`: 3/3 passed
   - Directional check: reverted the fix, re-ran the bind-failure test — failed as expected (requester never got a reply)
   - Full validation on CI (incl. multi-jvm suites which exercise `startController`)
   
   ### References
   Refs #3693


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] fix: answer conductor socket address queries asynchronously (#3693) [pekko]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on code in PR #3707:
URL: https://github.com/apache/pekko/pull/3707#discussion_r4371558563


##########
remote-tests/src/test/scala/org/apache/pekko/remote/testconductor/ControllerSpec.scala:
##########
@@ -49,6 +51,34 @@ class ControllerSpec extends PekkoSpec(ControllerSpec.config) with ImplicitSende
       c ! PoisonPill // clean up so network connections don't accumulate during test run
     }
 
+    "reply with the actually bound socket address" in {
+      val c = system.actorOf(Props(classOf[Controller], 1, new InetSocketAddress(InetAddress.getLocalHost, 0)))
+      c ! Controller.GetSockAddr
+      val addr = expectMsgType[InetSocketAddress]
+      addr.getPort should not be 0
+      c ! PoisonPill // clean up so network connections don't accumulate during test run
+    }
+
+    "reply with failure when the conductor port cannot be bound" in {
+      // bind to the same specific address the controller will use, a wildcard
+      // bind would not conflict on all platforms
+      val serverSocket = new ServerSocket(0, 50, InetAddress.getLocalHost)

Review Comment:
   Nit: this relies on a second bind to the same address and port failing even though the conductor server sets `SO_REUSEADDR` on non-Windows platforms. That holds on Linux and macOS while this socket is listening, and CI is green, but it's the one place I'd expect possible flakiness on other platforms or CI hosts. Not a blocker; just flagging it in case it shows up later.



##########
multi-node-testkit/src/main/scala/org/apache/pekko/remote/testconductor/Conductor.scala:
##########
@@ -529,7 +530,16 @@ private[pekko] class Controller(private var initialParticipants: Int, controller
       }
     case GetNodes    => sender() ! nodes.keys
     case GetSockAddr =>
-      sender() ! connection.channelFuture.sync().channel().localAddress()
+      val replyTo = sender()
+      // Netty also invokes listeners added after completion, so a failed bind
+      // is reported even when it finishes before the first address query.
+      connection.channelFuture.addListener((future: ChannelFuture) => {
+        val result = Try {
+          if (future.isSuccess) future.channel().localAddress()
+          else throw future.cause()
+        }
+        result.fold(cause => replyTo ! Status.Failure(cause), addr => replyTo ! addr)

Review Comment:
   Nit: the `Try { ... else throw future.cause() }.fold(...)` builds an exception path only to unpack it again, and if `cause` were fatal, `Try` would rethrow it on the Netty event loop. A direct branch is simpler:
   
   ```scala
   connection.channelFuture.addListener((future: ChannelFuture) =>
     if (future.isSuccess) replyTo ! future.channel().localAddress()
     else replyTo ! Status.Failure(future.cause()))
   ```
   
   That would also drop the `scala.util.Try` import.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org


Re: [PR] fix: answer conductor socket address queries asynchronously (#3693) [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin merged PR #3707:
URL: https://github.com/apache/pekko/pull/3707


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@pekko.apache.org
For additional commands, e-mail: notifications-help@pekko.apache.org