Copilot commented on code in PR #2915:
URL: https://github.com/apache/pekko/pull/2915#discussion_r3200511558
##########
actor/src/main/scala/org/apache/pekko/io/Tcp.scala:
##########
@@ -69,6 +69,13 @@ object Tcp extends ExtensionId[TcpExt] with
ExtensionIdProvider {
// general socket options
+ /**
+ * [[pekko.io.Inet.SocketOption]] to enable or disable SO_REUSEPORT
+ *
+ * For more information see [[java.net.StandardSocketOptions#SO_REUSEPORT]]
+ */
+ val ReusePort = Inet.SO.ReusePort
+
/**
Review Comment:
`ReusePort` is added directly here, but other shared socket options come
from `Inet.SoForwarders`. For consistency and to avoid duplicating the same
forwarding in multiple protocols, consider adding `ReusePort` to
`Inet.SoForwarders` (and then relying on the inherited forwarder here).
##########
actor/src/main/scala/org/apache/pekko/io/Inet.scala:
##########
@@ -16,12 +16,20 @@ package org.apache.pekko.io
import java.net.DatagramSocket
import java.net.ServerSocket
import java.net.Socket
+import java.net.StandardSocketOptions
import java.nio.channels.DatagramChannel
+import java.nio.channels.NetworkChannel
import scala.annotation.nowarn
object Inet {
+ private def setReusePort(channel: NetworkChannel, on: Boolean): Unit =
+ if (channel eq null)
+ throw new UnsupportedOperationException("SO_REUSEPORT can only be set on
channel-backed sockets")
+ else
+ channel.setOption(StandardSocketOptions.SO_REUSEPORT,
java.lang.Boolean.valueOf(on))
Review Comment:
`Inet.SO.ReusePort` uses `NetworkChannel.setOption(...)`, which can throw
`UnsupportedOperationException` when the platform/JDK does not support
`SO_REUSEPORT`. Several connection actors apply
`options.foreach(_.beforeConnect/beforeDatagramBind(...))` during actor
construction (e.g. outgoing TCP connects and some UDP paths), where such
exceptions are not wrapped into the usual `CommandFailed`/bind failure
reporting. This can result in the caller never receiving a failure response.
Consider ensuring socket-option application is performed inside existing
error-reporting blocks (or otherwise catching and converting failures so
callers reliably get `CommandFailed`).
##########
actor/src/main/scala/org/apache/pekko/io/Udp.scala:
##########
@@ -194,6 +194,13 @@ object Udp extends ExtensionId[UdpExt] with
ExtensionIdProvider {
*/
object SO extends Inet.SoForwarders {
+ /**
+ * [[pekko.io.Inet.SocketOption]] to enable or disable SO_REUSEPORT
+ *
+ * For more information see [[java.net.StandardSocketOptions#SO_REUSEPORT]]
+ */
+ val ReusePort = Inet.SO.ReusePort
+
Review Comment:
`ReusePort` is manually forwarded here; consider adding it to
`Inet.SoForwarders` (like `ReuseAddress`, `ReceiveBufferSize`, etc.) so all
protocol `SO` objects get consistent forwarders without per-file duplication.
##########
actor/src/main/scala/org/apache/pekko/io/Tcp.scala:
##########
@@ -69,6 +69,13 @@ object Tcp extends ExtensionId[TcpExt] with
ExtensionIdProvider {
// general socket options
+ /**
+ * [[pekko.io.Inet.SocketOption]] to enable or disable SO_REUSEPORT
+ *
+ * For more information see [[java.net.StandardSocketOptions#SO_REUSEPORT]]
+ */
+ val ReusePort = Inet.SO.ReusePort
Review Comment:
The PR description includes a reference link that uses the predecessor
project's name/repository. Project guidelines require avoiding that name in
PR/commit text; please replace the reference with a Pekko issue/PR link or
neutral wording.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]