Slow connection causes 'Missing metadata error'?

198 views
Skip to first unread message

Rémy Phelipot

unread,
Mar 11, 2016, 9:04:06 AM3/11/16
to ReactiveMongo - http://reactivemongo.org
Hello!

I'm using ReactiveMongo 0.11.7 and I encountered an error when I try to initialize a connection to a MongoDB cluster:

private[mongodb] object MongoContext {
 
/** MongoDB driver **/
  private val driver = new MongoDriver
 
/** MongoDB connection **/
  private val connection = driver.connection(
   
MongoConnection.parseURI("mongodb://localhost:27017/dbtest").get
 
)

 
/** Get a database connection **/
  import MongoUtils.executionContext
  def db: DB = connection(MongoConfiguration.mongoDBName)
}


2016-03-11 14:54:11 ERROR Failover2:51 - Got an error, no more attempts to do. Completing with a failure...
reactivemongo.core.errors.ConnectionNotInitialized: MongoError['Connection is missing metadata (like protocol version, etc.) The connection pool is probably being initialized.']
at reactivemongo.core.errors.ConnectionNotInitialized$.MissingMetadata(errors.scala:67)
at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1.apply(genericcollection.scala:268)
at reactivemongo.api.collections.GenericCollection$$anonfun$insert$1.apply(genericcollection.scala:251)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1253)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1346)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

If I change initialization method with the following, this error disappears.

private[mongodb] object MongoContext {
/** MongoDB driver **/
private val driver = new MongoDriver
/** MongoDB connection **/
private val connection = {
Await.result(this.futureConnection, MongoConfiguration.connectionTimeout)
}

private def futureConnection: Future[MongoConnection] = {
import scala.concurrent.ExecutionContext.Implicits.global
implicit val waitDuration = MongoConfiguration.connectionTimeout
val c = driver.connection(
MongoConnection.parseURI("mongodb://localhost:27017/dbtest-seeed-sm").get
)
c.waitForPrimary.map(_ => c)
}

/** Get a database connection **/
import MongoUtils.executionContext
def db: DB = connection(MongoConfiguration.mongoDBName)
}


Is this the expected behavior? Or I'm doing something wrong? Connections between client and the mongo hosts are unstable and might be the main source of the problem, but this error is not very helpful.

Cédric Chantepie

unread,
Mar 11, 2016, 11:10:13 AM3/11/16
to ReactiveMongo - http://reactivemongo.org
What MongoDB version are you using?

Rémy Phelipot

unread,
Mar 11, 2016, 11:43:22 AM3/11/16
to ReactiveMongo - http://reactivemongo.org
MongoDB version is 3.0.9.

Cédric Chantepie

unread,
Mar 11, 2016, 3:57:54 PM3/11/16
to ReactiveMongo - http://reactivemongo.org
I suggest you have a look at the connection documentation, and try to connect from a Scala console to one MongoDB server: http://reactivemongo.org/releases/0.11/documentation/tutorial/connect-database.html
Reply all
Reply to author
Forward
0 new messages