You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "goutamadwant (via GitHub)" <gi...@apache.org> on 2026/06/30 06:18:54 UTC

[PR] Close unregistered TCP channels on setup failure [pekko]

goutamadwant opened a new pull request, #3273:
URL: https://github.com/apache/pekko/pull/3273

   ### Motivation
   Outgoing TCP connection setup can fail before the connection actor receives a `ChannelRegistration`. In that path, `TcpConnection.postStop` reported `CommandFailed` but left the `SocketChannel` open because there was no registration callback available to close it.
   
   ### Modification
   Close still-open channels directly from `postStop` when no `ChannelRegistration` exists. Registered channels continue to use the existing `cancelAndClose` path.
   
   Also extend the existing connect socket option failure test to verify that the socket captured before the failed `beforeConnect` call is closed after `CommandFailed`.
   
   ### Result
   TCP setup failures before `ChannelRegistration` no longer leave the underlying `SocketChannel` open.
   
   ### Tests
   - `sbt "actor-tests / Test / testOnly org.apache.pekko.io.TcpIntegrationSpec"`
   - `sbt "actor / Compile / scalafmtCheck" "actor-tests / Test / scalafmtCheck"`
   - `git diff --check`
   
   ### References
   Fixes #3246


-- 
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] Close unregistered TCP channels on setup failure [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #3273:
URL: https://github.com/apache/pekko/pull/3273#discussion_r3498254354


##########
actor-tests/src/test/scala/org/apache/pekko/io/TcpIntegrationSpec.scala:
##########
@@ -187,8 +187,12 @@ class TcpIntegrationSpec extends PekkoSpec("""
     "reply with CommandFailed when a connect socket option fails before connect" in {
       val connectCommander = TestProbe()
       val failure = new UnsupportedOperationException("boom")
+      @volatile var socket: Socket = null

Review Comment:
   better with atomicRefernece



-- 
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] Close unregistered TCP channels on setup failure [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on code in PR #3273:
URL: https://github.com/apache/pekko/pull/3273#discussion_r3498260044


##########
actor/src/main/scala/org/apache/pekko/io/TcpConnection.scala:
##########
@@ -410,8 +410,15 @@ private[io] abstract class TcpConnection(val tcp: TcpExt, val channel: SocketCha
       (if (writePending) Set(pendingWrite.commander) else Set.empty) ++
       closedMessage.toList.flatMap(_.notificationsTo).toSet
 
-    if (channel.isOpen) // if channel is still open here, we didn't go through stopWith => unexpected actor termination
+    if (channel.isOpen) {
       prepareAbort()
+      // Without a ChannelRegistration there is no selector callback to close through.
+      if (registration.isEmpty)
+        try channel.close()
+        catch {
+          case NonFatal(e) => log.debug("Error closing SocketChannel: {}", e)

Review Comment:
   Error when closing?, and the `{}` should not be there and it should be  an error



-- 
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] Close unregistered TCP channels on setup failure [pekko]

Posted by "He-Pin (via GitHub)" <gi...@apache.org>.
He-Pin commented on PR #3273:
URL: https://github.com/apache/pekko/pull/3273#issuecomment-4840532072

   Thanks


-- 
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] Close unregistered TCP channels on setup failure [pekko]

Posted by "goutamadwant (via GitHub)" <gi...@apache.org>.
goutamadwant commented on PR #3273:
URL: https://github.com/apache/pekko/pull/3273#issuecomment-4886814747

   Thanks @He-Pin addressed both the comments. Let me know if you have any suggestions. 


-- 
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] Close unregistered TCP channels on setup failure [pekko]

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


-- 
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