You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@pekko.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/07/26 21:13:09 UTC

[PR] Close connection if execution takes too long [pekko-persistence-r2dbc]

pjfanning opened a new pull request, #457:
URL: https://github.com/apache/pekko-persistence-r2dbc/pull/457

   Ports https://github.com/akka/akka-persistence-r2dbc/pull/419 which is now available under Apache License, Version 2.0.


-- 
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 connection if execution takes too long [pekko-persistence-r2dbc]

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


##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/R2dbcExecutor.scala:
##########
@@ -319,27 +346,65 @@ class R2dbcExecutor(val connectionFactory: ConnectionFactory, log: Logger, logDb
         result.failed.foreach { exc =>
           log.debug("{} - DB call failed: {}", logPrefix: Any, exc: Any)
           // auto-commit so nothing to rollback
-          connection.close().asFutureDone()
+          val done = connection.close().asFutureDone()
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
         }
 
         result.flatMap { r =>
-          connection.close().asFutureDone().map { _ =>
-            val durationMicros = durationInMicros(startTime)
-            if (durationMicros >= logDbCallsExceedingMicros)
-              log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
-                durationMicros: java.lang.Long)
-            r
-          }
+          val done = connection
+            .close()
+            .asFutureDone()
+            .map { _ =>
+              val durationMicros = durationInMicros(startTime)
+              if (durationMicros >= logDbCallsExceedingMicros)
+                log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
+                  durationMicros: java.lang.Long)
+              r
+            }
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
+          done
         }
       }
     }
   }
 
   private def commitAndClose(connection: Connection): Future[Done] = {
-    connection.commitTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    connection.commitTransaction().asFutureDone().andThen { case _ =>
+      try connection.close().asFutureDone()
+      catch ignoreConnectionClosedException
+    }
   }
 
   private def rollbackAndClose(connection: Connection): Future[Done] = {
-    connection.rollbackTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    try connection
+        .rollbackTransaction()
+        .asFutureDone()
+        .andThen { case _ =>
+          try connection.close().asFutureDone()
+          catch ignoreConnectionClosedException
+
+        }
+    catch ignoreConnectionClosedException
+  }
+
+  private def closeAfterTimeout(connection: Connection): Unit = {

Review Comment:
   The timeout only covers withConnection and withAutoCommitConnection. select() still has no protection — a hung read query would leak a connection the same way. Matches upstream so not blocking, but worth a follow-up.



-- 
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 connection if execution takes too long [pekko-persistence-r2dbc]

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


##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/R2dbcExecutor.scala:
##########
@@ -319,27 +346,65 @@ class R2dbcExecutor(val connectionFactory: ConnectionFactory, log: Logger, logDb
         result.failed.foreach { exc =>
           log.debug("{} - DB call failed: {}", logPrefix: Any, exc: Any)
           // auto-commit so nothing to rollback
-          connection.close().asFutureDone()
+          val done = connection.close().asFutureDone()
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
         }
 
         result.flatMap { r =>
-          connection.close().asFutureDone().map { _ =>
-            val durationMicros = durationInMicros(startTime)
-            if (durationMicros >= logDbCallsExceedingMicros)
-              log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
-                durationMicros: java.lang.Long)
-            r
-          }
+          val done = connection
+            .close()
+            .asFutureDone()
+            .map { _ =>
+              val durationMicros = durationInMicros(startTime)
+              if (durationMicros >= logDbCallsExceedingMicros)
+                log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
+                  durationMicros: java.lang.Long)
+              r
+            }
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
+          done
         }
       }
     }
   }
 
   private def commitAndClose(connection: Connection): Future[Done] = {
-    connection.commitTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    connection.commitTransaction().asFutureDone().andThen { case _ =>
+      try connection.close().asFutureDone()
+      catch ignoreConnectionClosedException
+    }
   }
 
   private def rollbackAndClose(connection: Connection): Future[Done] = {
-    connection.rollbackTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    try connection
+        .rollbackTransaction()
+        .asFutureDone()
+        .andThen { case _ =>
+          try connection.close().asFutureDone()
+          catch ignoreConnectionClosedException
+
+        }

Review Comment:
   fixed in b51d1833270354ac444f8f0cb6ddaafcdf4e09b7



-- 
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 connection if execution takes too long [pekko-persistence-r2dbc]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #457:
URL: https://github.com/apache/pekko-persistence-r2dbc/pull/457


-- 
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 connection if execution takes too long [pekko-persistence-r2dbc]

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


##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/R2dbcExecutor.scala:
##########
@@ -319,27 +346,65 @@ class R2dbcExecutor(val connectionFactory: ConnectionFactory, log: Logger, logDb
         result.failed.foreach { exc =>
           log.debug("{} - DB call failed: {}", logPrefix: Any, exc: Any)
           // auto-commit so nothing to rollback
-          connection.close().asFutureDone()
+          val done = connection.close().asFutureDone()
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
         }
 
         result.flatMap { r =>
-          connection.close().asFutureDone().map { _ =>
-            val durationMicros = durationInMicros(startTime)
-            if (durationMicros >= logDbCallsExceedingMicros)
-              log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
-                durationMicros: java.lang.Long)
-            r
-          }
+          val done = connection
+            .close()
+            .asFutureDone()
+            .map { _ =>
+              val durationMicros = durationInMicros(startTime)
+              if (durationMicros >= logDbCallsExceedingMicros)
+                log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
+                  durationMicros: java.lang.Long)
+              r
+            }
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
+          done
         }
       }
     }
   }
 
   private def commitAndClose(connection: Connection): Future[Done] = {
-    connection.commitTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    connection.commitTransaction().asFutureDone().andThen { case _ =>
+      try connection.close().asFutureDone()
+      catch ignoreConnectionClosedException
+    }
   }
 
   private def rollbackAndClose(connection: Connection): Future[Done] = {
-    connection.rollbackTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    try connection
+        .rollbackTransaction()
+        .asFutureDone()
+        .andThen { case _ =>
+          try connection.close().asFutureDone()
+          catch ignoreConnectionClosedException
+
+        }

Review Comment:
   stray blank line before the catch



-- 
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 connection if execution takes too long [pekko-persistence-r2dbc]

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


##########
core/src/main/scala/org/apache/pekko/persistence/r2dbc/internal/R2dbcExecutor.scala:
##########
@@ -319,27 +346,65 @@ class R2dbcExecutor(val connectionFactory: ConnectionFactory, log: Logger, logDb
         result.failed.foreach { exc =>
           log.debug("{} - DB call failed: {}", logPrefix: Any, exc: Any)
           // auto-commit so nothing to rollback
-          connection.close().asFutureDone()
+          val done = connection.close().asFutureDone()
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
         }
 
         result.flatMap { r =>
-          connection.close().asFutureDone().map { _ =>
-            val durationMicros = durationInMicros(startTime)
-            if (durationMicros >= logDbCallsExceedingMicros)
-              log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
-                durationMicros: java.lang.Long)
-            r
-          }
+          val done = connection
+            .close()
+            .asFutureDone()
+            .map { _ =>
+              val durationMicros = durationInMicros(startTime)
+              if (durationMicros >= logDbCallsExceedingMicros)
+                log.info("{} - DB call completed [{}] in [{}] µs", logPrefix, Option(r).map(_.toString).orNull,
+                  durationMicros: java.lang.Long)
+              r
+            }
+          timeoutTask.foreach { task => done.onComplete(_ => task.cancel()) }
+          done
         }
       }
     }
   }
 
   private def commitAndClose(connection: Connection): Future[Done] = {
-    connection.commitTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    connection.commitTransaction().asFutureDone().andThen { case _ =>
+      try connection.close().asFutureDone()
+      catch ignoreConnectionClosedException
+    }
   }
 
   private def rollbackAndClose(connection: Connection): Future[Done] = {
-    connection.rollbackTransaction().asFutureDone().andThen { case _ => connection.close().asFutureDone() }
+    try connection
+        .rollbackTransaction()
+        .asFutureDone()
+        .andThen { case _ =>
+          try connection.close().asFutureDone()
+          catch ignoreConnectionClosedException
+
+        }
+    catch ignoreConnectionClosedException
+  }
+
+  private def closeAfterTimeout(connection: Connection): Unit = {

Review Comment:
   I'd prefer to keep this PR to be a copy of the Akka PR and any additional changes should be treated as a separate PR/issue. 



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