You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by en...@apache.org on 2024/07/07 11:58:07 UTC

(pekko-connectors) branch main updated: chore: add diagnostics to diagnose UnixDomainSocketSpec (#734)

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

engelen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pekko-connectors.git


The following commit(s) were added to refs/heads/main by this push:
     new 97e0b0813 chore: add diagnostics to diagnose UnixDomainSocketSpec (#734)
97e0b0813 is described below

commit 97e0b0813f4c3e759d98cd4a31eaaef2931729e3
Author: Arnout Engelen <ar...@bzzt.net>
AuthorDate: Sun Jul 7 13:58:01 2024 +0200

    chore: add diagnostics to diagnose UnixDomainSocketSpec (#734)
    
    Looking at `UnixDomainSocketImpl#outgoingConnection`, this test failure
    can/should only happen when both `connectionFlow` and `connectionFinished`
    complete successfully.
    
    There seems to be potential race between `UnixDomainSocketImpl#connectKey` and
    `channel.connect` both completing `connectionFinished`, though this
    seems strange. This PR is meant to add diagnostic logging so next time
    the test fails we can confirm whether this is indeed what's going on.
---
 .../unixdomainsocket/impl/UnixDomainSocketImpl.scala  | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/unix-domain-socket/src/main/scala/org/apache/pekko/stream/connectors/unixdomainsocket/impl/UnixDomainSocketImpl.scala b/unix-domain-socket/src/main/scala/org/apache/pekko/stream/connectors/unixdomainsocket/impl/UnixDomainSocketImpl.scala
index 51b846ef3..ab8b1dbda 100644
--- a/unix-domain-socket/src/main/scala/org/apache/pekko/stream/connectors/unixdomainsocket/impl/UnixDomainSocketImpl.scala
+++ b/unix-domain-socket/src/main/scala/org/apache/pekko/stream/connectors/unixdomainsocket/impl/UnixDomainSocketImpl.scala
@@ -271,20 +271,22 @@ private[unixdomainsocket] object UnixDomainSocketImpl {
     }
   }
 
-  private def connectKey(remoteAddress: JnrUnixSocketAddress,
-      connectionFinished: Promise[Done],
+  private def connectKey(connectionFinished: Promise[Done],
       cancellable: Option[Cancellable],
-      sendReceiveContext: SendReceiveContext)(sel: Selector, key: SelectionKey): Unit = {
+      sendReceiveContext: SendReceiveContext,
+      log: LoggingAdapter)(sel: Selector, key: SelectionKey): Unit = {
 
     val connectingChannel = key.channel().asInstanceOf[UnixSocketChannel]
     cancellable.foreach(_.cancel())
     try {
       connectingChannel.register(sel, SelectionKey.OP_READ, sendReceiveContext)
       val finishExpected = connectingChannel.finishConnect()
+      log.debug(s"Unix domain socket connection succeeded, finish $finishExpected")
       require(finishExpected, "Internal error - our call to connection finish wasn't expected.")
       connectionFinished.trySuccess(Done)
     } catch {
       case NonFatal(e) =>
+        log.debug("Unix domain socket connection failed")
         connectionFinished.tryFailure(e)
         key.cancel()
     }
@@ -481,11 +483,18 @@ private[unixdomainsocket] abstract class UnixDomainSocketImpl(system: ExtendedAc
         }
       val (context, connectionFlow) = sendReceiveStructures(sel, receiveBufferSize, sendBufferSize, halfClose)
       val ra = new JnrUnixSocketAddress(remoteAddress.path.toFile)
+      val log = system.log
       val registeredKey =
         channel
-          .register(sel, SelectionKey.OP_CONNECT, connectKey(ra, connectionFinished, cancellable, context) _)
+          .register(sel, SelectionKey.OP_CONNECT, connectKey(connectionFinished, cancellable, context, log) _)
       val connection = Try(channel.connect(ra))
-      connection.failed.foreach(e => connectionFinished.tryFailure(e))
+      connection.failed.foreach { e =>
+        if (connectionFinished.tryFailure(e)) {
+          log.debug("Unix domain socket channel connect failed")
+        } else {
+          log.debug("Unix domain socket channel connect failed, but connectionFinished had already completed")
+        }
+      }
 
       Future.successful(
         connectionFlow


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