-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Infinite retries when unable to open a Connection #194
Comments
Adding that using |
The piece of code that relates to this in zio-jdbc is zio-jdbc/core/src/main/scala/zio/jdbc/ZConnectionPool.scala Lines 115 to 122 in cfd8a7e
And the default retry config is supposed to be max 10 times: zio-jdbc/core/src/main/scala/zio/jdbc/ZConnectionPoolConfig.scala Lines 35 to 36 in cfd8a7e
|
For anyone stumbling across this, I would like to offer some more insights. From my understanding, what is actually happening are not actually infinite retries, but instead the retry policy of the connection pool is applied to every potentially available connection from the pool. To illustrate what I mean consider the below scala-cli script: #!/usr/bin/env -S scala-cli shebang
//> using dep "dev.zio::zio-jdbc:0.1.2"
//> using dep "dev.zio::zio-streams:2.1.6"
//> using dep "dev.zio::zio:2.1.6"
//> using dep "org.postgresql:postgresql:42.7.3"
import zio.*
import zio.jdbc.*
import zio.stream.*
object App extends ZIOAppDefault:
val retryPolicy = Schedule.stop.tapOutput(_ => ZIO.logInfo("failed"))
val connectionPoolConfig =
ZLayer.succeed:
ZConnectionPoolConfig
.default
.copy(
minConnections = 0,
maxConnections = 1,
retryPolicy = retryPolicy,
)
val connectionPool =
val props = Map("user" -> "postgres", "password" -> "password")
ZConnectionPool.postgres("postgres", 5432, "postgres", props)
val query = sql"select count(*) from test".query[Int]
val logic =
for
count <- transaction(query.selectOne).flatMap(ZIO.fromOption)
_ <- ZIO.logInfo(s"count is $count")
yield ()
override def run = logic.provide(connectionPoolConfig, connectionPool)
App.main(args) This script will log the |
I didn't read in details the issue but I fixed something similar some times ago here: #174 |
I'm pretty sure #174 was already included when I reported the issue. I mean the issue is still there. |
Context
I've noticed a strange behavior which I'm attributing to zio-jdbc but it could actually be caused by ZIO core. I don't know enough of the details to be affirmative here.
Versions
Observed behaviour
When a
Connection
cannot be opened with the database due to a connection timeout for instance (or any other error blocking long enough, in my reproduction scenario it's 30s but on the real case I observed it was 2 minutes), the retry logic seems to be misbehaving and the application retries infinitely instead of crashing.Reproduction scenario
Here's a reproduction test using Scalatest:
When running this test, here's the output:
You can notice that after reaching the 10 retries defined in the retry policy, it starts again to retry back at iteration 0.
Other
If the "long operation" is not that long (1s instead of 30s for instance), the behaviour is not the same: the app crashes as expected after 10 retries.
The text was updated successfully, but these errors were encountered: