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: [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]

Reply via email to