0.13.0 connection.database() blocks

35 views
Skip to first unread message

Francis De Brabandere

unread,
Feb 19, 2018, 8:01:33 AM2/19/18
to ReactiveMongo - http://reactivemongo.org
It seems that the following code is blocking when the database is not available (0.13.0)

private final val testFailoverStrategy = FailoverStrategy(retries = 40)
val connection = driver.connection(parsedUri)
// the next line blocks
val db = connection.database(parsedUri.db.get, testFailoverStrategy)


Is this expected? This returns a Future[DefaultDB] so I see no reason to block the calling thread.

Thanks,
F

Cédric Chantepie

unread,
Feb 20, 2018, 6:40:10 AM2/20/18
to ReactiveMongo - http://reactivemongo.org
What make you think it's blocking? (BTW there has been no change about the connection/database resolution in this release).

scala> c.database(dbName).map { _ => println("_database") }; println("Foo")
Foo
_database


Francis De Brabandere

unread,
Feb 20, 2018, 7:19:58 AM2/20/18
to reacti...@googlegroups.com
It made me think that because our server is not starting when the database is down. It hangs on the "val db = ..." line.

--
You received this message because you are subscribed to a topic in the Google Groups "ReactiveMongo - http://reactivemongo.org" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/reactivemongo/-BpcLtvVm9g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to reactivemongo+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Cédric Chantepie

unread,
Feb 20, 2018, 9:18:08 AM2/20/18
to ReactiveMongo - http://reactivemongo.org
As you see in the pasted test, `database(..)` is not blocking.

BTW, assigning such resolution to a `val` is highly discouraged (as indicated in the documentation).

Francis De Brabandere

unread,
Feb 20, 2018, 11:12:45 AM2/20/18
to reacti...@googlegroups.com
For production we use a def

I wonder how your code can print "_database" if the database is down and the Future fails

val start = Instant.now()
val f = connection.database("test").map { _ => println("_database") }
val duration = java.time.Duration.between(start, Instant.now())
println( s"$duration Foo")

All I see logged is "PT8.203S Foo", so the call blocks for 8.2 seconds before returning a failed future

On 20 February 2018 at 15:18, Cédric Chantepie <chantep...@gmail.com> wrote:
As you see in the pasted test, `database(..)` is not blocking.

BTW, assigning such resolution to a `val` is highly discouraged (as indicated in the documentation).

--

Cédric Chantepie

unread,
Feb 20, 2018, 5:51:49 PM2/20/18
to ReactiveMongo - http://reactivemongo.org
You can try 0.13.1-SNAPSHOT (seems some timeout issue was there since 0.11/0.12).
Reply all
Reply to author
Forward
0 new messages