[JAVA-3855] No diagnostic of connect fault to database Created: 09/Oct/20 Updated: 09/Oct/20 Resolved: 09/Oct/20 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Andrew Kaplanov | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
That is fragment of Scala program that calls objects from com.mongodb.reactivestreams: val client = MongoClients.create() db.listCollectionNames().subscribe(new Subscriber[String] { def onSubscribe(s: Subscription) = println("onSubscribe") def onNext(elem: String) = println("onNext") def onError(t: Throwable) = println("onError") def onComplete() = println("onComplete") })
When database is not exist, I see on console: onSubscribe 00:27:13.696 INFO org.mongodb.driver.cluster - Exception in monitor thread while connecting to server localhost:27017 ... But OnError is not called. How can I handle this error? |
| Comments |
| Comment by Andrew Kaplanov [ 09/Oct/20 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Thank you. But the reason is not only in back-pressure in my test. You sample contains setting to MongoClient "builder.serverSelectionTimeout(1, TimeUnit.SECONDS)". So onError() prints the error "com.mongodb.MongoTimeoutException: Timed out after 1000 ms while waiting for a server ..." In case when MongoClient creates with default settings, onError() is called after 30 sec, that is default timeout. I think it is wrong. Database connection error should return immediately.
| ||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 09/Oct/20 ] | ||||||||||||||||||||||||||||||||||||||||||
|
I think there is a misunderstanding about how reactive publishers work; the Subscriber has to first request events from the publisher before anything will actually start happening. It's easier for me to show using the Java Reactive Streams driver, so please forgive me for not using Scala:
When I run this program with no mongod available, I get the following output:
| ||||||||||||||||||||||||||||||||||||||||||
| Comment by Andrew Kaplanov [ 09/Oct/20 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Thanks to you. It is unacceptable for me that I see connection error only on console, but I can't handle this error in my program. I can't check result of getDatabase() call. Other calls return Publisher. Attempting to read Publisher hangs because not either onError or onComplete called. | ||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 09/Oct/20 ] | ||||||||||||||||||||||||||||||||||||||||||
|
Thanks for your question. I moved this to the JAVA project as that is where we are now tracking all Scala and Reactive Streams issues. We'll take a look at it soon and get back to you. |