MongoDb中的偶发(Authentication ??)失败和过期

时间:2016-02-17 11:00:43

标签: mongodb scala docker reactivemongo akka-http

连接到MongoDB副本集时遇到一些问题。 我创建了一个用于读写的mongodb管理员用户。我可以成功登录终端上的mongo shell,会话永远不会过期。

在我的scala应用程序中,我运行带有reactivemongo 0.11.9的akka​​-http和MongoDB 3.2.1,在3个独立服务器上的Docker容器中设置mongo复制,并为其各自的主机提供持久存储。我正在验证服务器启动时的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$2.apply(api.scala:117) [reactivemongo_2.11-0.11.9.jar:0.11.9]
    at reactivemongo.api.Failover2$$anonfun$reactivemongo$api$Failover2$$send$2.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$1.apply$mcV$sp(BatchingExecutor.scala:91) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91) [akka-actor_2.11-2.4.1.jar:?]
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.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$2.apply(api.scala:117)
    at reactivemongo.api.Failover2$$anonfun$reactivemongo$api$Failover2$$send$2.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$1.apply$mcV$sp(BatchingExecutor.scala:91)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.apply(BatchingExecutor.scala:91)
    at akka.dispatch.BatchingExecutor$BlockableBatch$$anonfun$run$1.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连接失败而导致另一个原因,如果连接由于其他原因而失败,为什么它不会恢复并找到要写入的主要?有没有其他人看过或有这个问题或类似的问题?

1 个答案:

答案 0 :(得分:0)

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

0.11.9不适用于MongoDb 3.2.1

0.11.10适用于MongoDb 3.2.1