MongoDb 中的零星(身份验证??)失败和过期

Sporadic (Authentication??) Failures and Expirations in MongoDb

我在连接到 MongoDB 副本集时遇到了一些问题。 我创建了一个 mongodb admin 用户用于读写。我可以在终端上成功登录 mongo shell,并且会话从未过期。

在我的 scala 应用程序中,我是 运行 akka-http,带有反应式mongo 0.11.9 和 MongoDB 3.2.1,其中 mongo 复制设置在 Docker 3 个独立服务器上的容器,持久存储到各自的主机。我在服务器启动时验证 mongo 连接。

大约 60% 的时间它会暂时工作(40% 的时间它在启动时无法通过身份验证)并且在 5-20 分钟后,我的连接不再经过身份验证或者连接已经终止并且无法重新连接。我在任何地方都没有发现任何关于保持身份验证打开更长时间或者为什么连接只会断开而不是恢复的任何地方,并且看到身份验证在连接级别是如何进行的,只要连接存在就应该保持身份验证。

这是我的 mongo 连接对象:

class MongodbDataStore(implicit exec: ExecutionContext) {

 var driver1 = new reactivemongo.api.MongoDriver
 var mongoOptions = new MongoConnectionOptions(nbChannelsPerNode = 5,
                                               connectTimeoutMS = 300000, 
                                               authMode = ScramSha1Authentication)
 var counter = 0
 val dbName = "admin"
 val userName = "name"
 val password = "password"
 val credentials = List(Authenticate(dbName, userName, password))
 var connection3 = Array(driver1.connection(List("X.X.X.X","X.X.X.X","X.X.X.X"), mongoOptions, authentications = credentials))

 def getdb: BSONCollection = {
   counter = counter + 1
   val database: reactivemongo.api.DB = connection3(0).db("database")
   database.collection[BSONCollection]("collection")
 }

}

身份验证过期后,我收到此错误:

reactivemongo.core.errors.GenericDriverException: MongoError['socket disconnected']
18:23:58.655 [reactivemongo-akka.actor.default-dispatcher-3] ERROR reactivemongo.core.actors.MongoDBSystem - The primary is unavailable, is there a network problem?
18:23:58.655 [reactivemongo-akka.actor.default-dispatcher-3] ERROR reactivemongo.core.actors.MongoDBSystem - The primary is unavailable, is there a network problem?
18:23:59.092 [ReactiveKafka-akka.actor.default-dispatcher-9] ERROR reactivemongo.api.Failover2 - Got an error, no more attempts to do. Completing with a failure...
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$: MongoError['No primary node is available!']
    at reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.<clinit>(actors.scala) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.api.Failover2.reactivemongo$api$Failover2$$isRetryable(api.scala:139) ~[reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.api.Failover2$$anonfun$reactivemongo$api$Failover2$$send.apply(api.scala:117) [reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.api.Failover2$$anonfun$reactivemongo$api$Failover2$$send.apply(api.scala:116) [reactivemongo_2.11-0.11.9.jar:0.11.9]
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library-2.11.7.jar:?]
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run.apply$mcV$sp(BatchingExecutor.scala:91) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run.apply(BatchingExecutor.scala:91) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run.apply(BatchingExecutor.scala:91) [akka-actor_2.11-2.4.1.jar:?]
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72) [scala-library-2.11.7.jar:?]
    at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:90) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:399) [akka-actor_2.11-2.4.1.jar:?]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library-2.11.7.jar:?]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library-2.11.7.jar:?]
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library-2.11.7.jar:?]
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library-2.11.7.jar:?]
[ERROR] [02/17/2016 18:23:59.093] [ReactiveKafka-akka.actor.default-dispatcher-9] [akka.actor.ActorSystemImpl(ReactiveKafka)] Error during processing of request HttpRequest(HttpMethod(POST),http://127.0.0.1:9001/user_login,List(Host: 127.0.0.1:9001, Connection: keep-alive, Cache-Control: no-cache, Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop, User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36, Postman-Token:..., Accept: */*, Accept-Encoding: gzip, deflate, Accept-Language: en-US, en;q=0.8),HttpEntity.Strict(application/json,ByteString(32, 32, 32, 32, 32, 32, 32, 123, 34, 107, 101, 121, 34, 58, 34, 117, 83, 101, 68, 84, 111, 67, 97, 76, 108, 77, 69, 111, 78, 109, 89, 67, 69, 108, 108, 80, 104, 79, 110, 51, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 112, 104, 111, 110, 101, 78, 117, 109, 98, 101, 114, 34, 58, 34, 49, 55, 55, 50, 49, 50, 52, 56, 51, 52, 49, 34, 44, 10, 32, 32, 32, 32, 32, 32, 32, 32, 34, 112, 97, 115, 115, 119, 111, 114, 100, 34, 58, 34)... and [16] more),HttpProtocol(HTTP/1.1))
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$: MongoError['No primary node is available!']
    at reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.<clinit>(actors.scala)
    at reactivemongo.api.Failover2.reactivemongo$api$Failover2$$isRetryable(api.scala:139)
    at reactivemongo.api.Failover2$$anonfun$reactivemongo$api$Failover2$$send.apply(api.scala:117)
    at reactivemongo.api.Failover2$$anonfun$reactivemongo$api$Failover2$$send.apply(api.scala:116)
    at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32)
    at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run.apply$mcV$sp(BatchingExecutor.scala:91)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run.apply(BatchingExecutor.scala:91)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run.apply(BatchingExecutor.scala:91)
    at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:72)
    at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:90)
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:39)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:399)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

我是否缺少有关身份验证过期的设置?是否有可能 mongo 连接因其他原因而失败,如果连接因其他原因而失败,为什么它不能恢复并找到要写入的主服务器?有没有其他人看到或遇到过这个问题或类似问题?

事实证明错误是由于 ReactiveMongo 不支持最新的 MongoDB。一旦 ReactiveMongo 发布更新,一切正常。

0.11.9 不适用于 MongoDb 3.2.1

0.11.10 确实适用于 MongoDb 3.2.1