Reactivemongo leaking connections during Play hot-reload - scala

I have a Scala-based Play app that uses ReactiveMongo. When in development mode and a hot-reload occurs, ReactiveMongo leaks connections. For example, here is a snippet of Mongo's log files; I added a line break in the logs to indicate each time a hot-reload occurred (i.e. I made a trivial change the app and reloaded a page in the browser)
2015-09-26T09:43:43.353-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58612 #1 (1 connection now open)
2015-09-26T09:43:43.725-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58613 #2 (2 connections now open)
2015-09-26T09:43:43.725-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58614 #3 (3 connections now open)
2015-09-26T09:43:43.725-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58615 #4 (4 connections now open)
2015-09-26T09:43:43.725-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58616 #5 (5 connections now open)
2015-09-26T09:43:43.726-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58617 #6 (6 connections now open)
2015-09-26T09:43:43.726-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58618 #7 (7 connections now open)
2015-09-26T09:43:43.726-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58619 #8 (8 connections now open)
2015-09-26T09:43:43.726-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58620 #9 (9 connections now open)
2015-09-26T09:43:43.726-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58621 #10 (10 connections now open)
2015-09-26T09:43:43.810-0700 I INDEX [conn1] build index on: sma.destination properties: { v: 1, unique: true, key: { id: 1 }, name: "idx_destination_id", ns: "sma.destination" }
2015-09-26T09:43:43.810-0700 I INDEX [conn1] building index using bulk method
2015-09-26T09:43:57.164-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58640 #11 (11 connections now open)
2015-09-26T09:43:57.169-0700 I NETWORK [conn11] end connection 127.0.0.1:58640 (10 connections now open)
2015-09-26T09:43:57.431-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58641 #12 (11 connections now open)
2015-09-26T09:43:57.435-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58642 #13 (12 connections now open)
2015-09-26T09:43:57.436-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58643 #14 (13 connections now open)
2015-09-26T09:43:57.436-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58644 #15 (14 connections now open)
2015-09-26T09:43:57.437-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58645 #16 (15 connections now open)
2015-09-26T09:43:57.437-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58646 #17 (16 connections now open)
2015-09-26T09:43:57.437-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58647 #18 (17 connections now open)
2015-09-26T09:43:57.437-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58648 #19 (18 connections now open)
2015-09-26T09:43:57.437-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58649 #20 (19 connections now open)
2015-09-26T09:43:57.437-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58650 #21 (20 connections now open)
2015-09-26T09:43:57.487-0700 I INDEX [conn14] build index on: sma.destination properties: { v: 1, unique: true, key: { id: 1 }, name: "idx_destination_id", ns: "sma.destination" }
2015-09-26T09:43:57.487-0700 I INDEX [conn14] building index using bulk method
2015-09-26T09:44:16.559-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58677 #22 (21 connections now open)
2015-09-26T09:44:16.560-0700 I NETWORK [conn22] end connection 127.0.0.1:58677 (20 connections now open)
2015-09-26T09:44:16.766-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58678 #23 (21 connections now open)
2015-09-26T09:44:16.770-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58679 #24 (22 connections now open)
2015-09-26T09:44:16.771-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58680 #25 (23 connections now open)
2015-09-26T09:44:16.771-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58681 #26 (24 connections now open)
2015-09-26T09:44:16.771-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58682 #27 (25 connections now open)
2015-09-26T09:44:16.772-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58683 #28 (26 connections now open)
2015-09-26T09:44:16.772-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58684 #29 (27 connections now open)
2015-09-26T09:44:16.772-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58685 #30 (28 connections now open)
2015-09-26T09:44:16.772-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58686 #31 (29 connections now open)
2015-09-26T09:44:16.772-0700 I NETWORK [initandlisten] connection accepted from 127.0.0.1:58687 #32 (30 connections now open)
2015-09-26T09:44:16.791-0700 I INDEX [conn24] build index on: sma.destination properties: { v: 1, unique: true, key: { id: 1 }, name: "idx_destination_id", ns: "sma.destination" }
2015-09-26T09:44:16.792-0700 I INDEX [conn24] building index using bulk method
You can see that ReactiveMongo creates a pool of 10 connections each time a hot-reload occurs; the previous 10 connections don't get cleaned up. Eventually it gets to the max number of connections (currently ~ 200), and then mongo becomes inaccessible until I restart.
Presumably this wouldn't happen in prod, but I'm a little unnerved by it happening in dev in the first place. Is there any way I can close those connections when the app hot-reloads?

Had the same problem following slightly outdated tutorials (using Play 2.6)
From the docs:
http://reactivemongo.org/releases/0.12/documentation/tutorial/play.html
/*
* Get a JSONCollection (a Collection implementation that is designed to work
* with JsObject, Reads and Writes.)
* Note that the `collection` is not a `val`, but a `def`. We do _not_ store
* the collection reference to avoid potential problems in development with
* Play hot-reloading.
*/
def collection: Future[JSONCollection] = database.map(
_.collection[JSONCollection]("persons"))
In my case, replacing: val collection: JSonCollection to the format above solved my problem.
Now when reloading, it closes and reopens all the connections:
2017-08-15T15:32:50.991-0300 I - [conn2] end connection 127.0.0.1:58489 (10 connections now open)
2017-08-15T15:32:50.992-0300 I - [conn9] end connection 127.0.0.1:58496 (9 connections now open)
2017-08-15T15:32:50.992-0300 I - [conn4] end connection 127.0.0.1:58491 (8 connections now open)
2017-08-15T15:32:50.993-0300 I - [conn5] end connection 127.0.0.1:58492 (7 connections now open)
2017-08-15T15:32:50.994-0300 I - [conn6] end connection 127.0.0.1:58493 (6 connections now open)
and so on...

Related

MongoDB log file shows connection accepted & end connection constantly

I'm trying to install MongoDb server in Redhat 7 GCE
After starting Mongod process with replication, the mongolog shows an error log..
`2017-12-29T20:51:12.853+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38130 #53 (1 connection now open)
2017-12-29T20:51:42.861+0530 I NETWORK [conn53] end connection
10.142.0.2:38130 (0 connections now open)
2017-12-29T20:51:42.862+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38136 #54 (1 connection now open)
2017-12-29T20:52:12.868+0530 I NETWORK [conn54] end connection
10.142.0.2:38136 (0 connections now open)
2017-12-29T20:52:12.869+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38144 #55 (1 connection now open)
2017-12-29T20:52:42.877+0530 I NETWORK [conn55] end connection
10.142.0.2:38144 (0 connections now open)
2017-12-29T20:52:42.877+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38150 #56 (1 connection now open)
2017-12-29T20:53:12.883+0530 I NETWORK [conn56] end connection
10.142.0.2:38150 (0 connections now open)
2017-12-29T20:53:12.883+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38156 #57 (1 connection now open)
2017-12-29T20:53:42.891+0530 I NETWORK [conn57] end connection
10.142.0.2:38156 (0 connections now open)
2017-12-29T20:53:42.892+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38162 #58 (1 connection now open)
2017-12-29T20:54:12.900+0530 I NETWORK [conn58] end connection
10.142.0.2:38162 (0 connections now open)
2017-12-29T20:54:12.900+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38170 #59 (1 connection now open)
2017-12-29T20:54:42.908+0530 I NETWORK [conn59] end connection
10.142.0.2:38170 (0 connections now open)
2017-12-29T20:54:42.908+0530 I NETWORK [initandlisten] connection accepted
from 10.142.0.2:38174 #60 (1 connection now open)
2017-12-29T20:55:12.917+0530 I NETWORK [conn60] end connection
10.142.0.2:38174 (0 connections now open)
`
I can connect from the redhat shell as
mongo --port 34672
but when i try to connect from an external ip it fails.
i was not able to find the reason for this error after checking all the error logs and searching in the web.
These log entries to not indicate an error. It is simply reporting connections. As for the reason for the connections, there could be several:
If you have an application using MongoDB, these connections are likely coming from that application.
If you have monitoring such as Stackdriver Monitoring installed, these could be connections from the monitoring to fetch statistics from MongoDB.
If you are using a cluster of MongoDB servers, this could be connections or health-checking between them.
I think (2) or (3) are especially likely, given that they are coming from internal IP addresses are are spaced exactly 30 seconds apart.
I believe your issue connecting externally is unrelated to these messages. If that is what you are really concerned about, I suggest you open a new question about that.

stuck of start mongoDB

2017-03-01T00:51:32.863-0500 I CONTROL [initandlisten]
2017-03-01T00:51:33.271-0500 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'D:/mongo/data/diagnostic.data'
2017-03-01T00:51:33.284-0500 I NETWORK [thread1] waiting for connections on port 27017
2017-03-01T00:51:33.391-0500 I NETWORK [thread1] connection accepted from 127.0.0.1:50501 #1 (1 connection now open)
2017-03-01T00:51:33.394-0500 I NETWORK [thread1] connection accepted from 127.0.0.1:50502 #2 (2 connections now open)
2017-03-01T00:51:33.399-0500 I NETWORK [thread1] connection accepted from 127.0.0.1:50503 #3 (3 connections now open)
2017-03-01T00:51:33.401-0500 I NETWORK [thread1] connection accepted from 127.0.0.1:50504 #4 (4 connections now open)
2017-03-01T00:51:33.406-0500 I NETWORK [thread1] connection accepted from 127.0.0.1:50505 #5 (5 connections now open)
2017-03-01T00:51:33.418-0500 I NETWORK [thread1] connection accepted from 127.0.0.1:50506 #6 (6 connections now open)
When I start the mongoDB, the command line pop up these things, how could I fix it? I have tried delete the data folder...

Strange MongoError (with ReactiveMongo) when Play reloads application

Very often, when Play reloads the application after a code change, I receive the following error:
MongoError['The node set can not be reached! Please check your network
connectivity.']
The MongoDB log looks like this:
2016-09-06T18:51:22.609+0200 I NETWORK [initandlisten] waiting for connections on port 27017
2016-09-06T18:53:49.916+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60559 #1 (1 connection now open)
2016-09-06T18:53:51.185+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60561 #2 (2 connections now open)
2016-09-06T18:53:51.196+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60562 #3 (3 connections now open)
2016-09-06T18:53:51.206+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60563 #4 (4 connections now open)
2016-09-06T18:53:51.217+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60564 #5 (5 connections now open)
2016-09-06T18:53:51.227+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60565 #6 (6 connections now open)
2016-09-06T18:53:51.237+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60566 #7 (7 connections now open)
2016-09-06T18:53:51.248+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60567 #8 (8 connections now open)
2016-09-06T18:53:51.258+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60568 #9 (9 connections now open)
2016-09-06T18:53:51.269+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60569 #10 (10 connections now open)
2016-09-06T18:53:59.533+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60577 #11 (11 connections now open)
2016-09-06T18:53:59.546+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60578 #12 (12 connections now open)
2016-09-06T18:53:59.557+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60579 #13 (13 connections now open)
2016-09-06T18:53:59.568+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60580 #14 (14 connections now open)
2016-09-06T18:53:59.579+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60581 #15 (15 connections now open)
2016-09-06T18:53:59.589+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60582 #16 (16 connections now open)
2016-09-06T18:53:59.600+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60583 #17 (17 connections now open)
2016-09-06T18:53:59.610+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60584 #18 (18 connections now open)
2016-09-06T18:53:59.620+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:60585 #19 (19 connections now open)
2016-09-06T19:37:21.594+0200 I NETWORK [conn11] end connection 127.0.0.1:60577 (18 connections now open)
2016-09-06T19:37:21.596+0200 I NETWORK [conn1] end connection 127.0.0.1:60559 (17 connections now open)
2016-09-06T19:37:21.597+0200 I NETWORK [conn15] end connection 127.0.0.1:60581 (16 connections now open)
2016-09-06T19:37:21.597+0200 I NETWORK [conn13] end connection 127.0.0.1:60579 (15 connections now open)
2016-09-06T19:37:21.597+0200 I NETWORK [conn16] end connection 127.0.0.1:60582 (14 connections now open)
2016-09-06T19:37:21.598+0200 I NETWORK [conn12] end connection 127.0.0.1:60578 (13 connections now open)
2016-09-06T19:37:21.598+0200 I NETWORK [conn19] end connection 127.0.0.1:60585 (13 connections now open)
2016-09-06T19:37:21.599+0200 I NETWORK [conn17] end connection 127.0.0.1:60583 (11 connections now open)
2016-09-06T19:37:21.599+0200 I NETWORK [conn14] end connection 127.0.0.1:60580 (11 connections now open)
2016-09-06T19:37:21.600+0200 I NETWORK [conn18] end connection 127.0.0.1:60584 (9 connections now open)
2016-09-06T19:37:21.607+0200 I NETWORK [conn5] end connection 127.0.0.1:60564 (9 connections now open)
2016-09-06T19:37:21.607+0200 I NETWORK [conn9] end connection 127.0.0.1:60568 (9 connections now open)
2016-09-06T19:37:21.608+0200 I NETWORK [conn6] end connection 127.0.0.1:60565 (9 connections now open)
2016-09-06T19:37:21.608+0200 I NETWORK [conn10] end connection 127.0.0.1:60569 (9 connections now open)
2016-09-06T19:37:21.609+0200 I NETWORK [conn2] end connection 127.0.0.1:60561 (9 connections now open)
2016-09-06T19:37:21.609+0200 I NETWORK [conn7] end connection 127.0.0.1:60566 (9 connections now open)
2016-09-06T19:37:21.610+0200 I NETWORK [conn3] end connection 127.0.0.1:60562 (9 connections now open)
2016-09-06T19:37:21.611+0200 I NETWORK [conn4] end connection 127.0.0.1:60563 (4 connections now open)
2016-09-06T19:37:21.612+0200 I NETWORK [conn8] end connection 127.0.0.1:60567 (0 connections now open)
2016-09-06T19:37:22.326+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62077 #20 (1 connection now open)
2016-09-06T19:37:22.333+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62078 #21 (2 connections now open)
2016-09-06T19:37:22.333+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62079 #22 (3 connections now open)
2016-09-06T19:37:22.343+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62080 #23 (4 connections now open)
2016-09-06T19:37:22.344+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62081 #24 (5 connections now open)
2016-09-06T19:37:22.344+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62082 #25 (6 connections now open)
2016-09-06T19:37:22.344+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62083 #26 (7 connections now open)
2016-09-06T19:37:22.344+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62084 #27 (8 connections now open)
2016-09-06T19:37:22.354+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62085 #28 (9 connections now open)
2016-09-06T19:37:22.355+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62086 #29 (10 connections now open)
2016-09-06T19:37:32.348+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62105 #30 (11 connections now open)
2016-09-06T19:37:32.359+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62106 #31 (12 connections now open)
2016-09-06T19:37:32.393+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62107 #32 (13 connections now open)
2016-09-06T19:37:32.399+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62108 #33 (14 connections now open)
2016-09-06T19:37:32.399+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62109 #34 (15 connections now open)
2016-09-06T19:37:32.399+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62110 #35 (16 connections now open)
2016-09-06T19:37:32.399+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62111 #36 (17 connections now open)
2016-09-06T19:37:32.401+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62112 #37 (18 connections now open)
2016-09-06T19:37:32.401+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:62113 #38 (19 connections now open)
Sometimes there's also this exception:
[warn] r.c.a.MongoDBSystem - The entire node set is unreachable, is there a network problem?
[warn] r.c.a.MongoDBSystem - The entire node set is unreachable, is there a network problem?
[error] r.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)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:748)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:748)
at scala.Option.getOrElse(Option.scala:121)
at reactivemongo.core.actors.MongoDBSystem$class.reactivemongo$core$actors$MongoDBSystem$$pickChannel(actors.scala:748)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$4.applyOrElse(actors.scala:340)
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:170)
at akka.actor.Actor$class.aroundReceive(Actor.scala:482)
at reactivemongo.core.actors.LegacyDBSystem.aroundReceive(actors.scala:896)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
[error] r.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)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:748)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:748)
at scala.Option.getOrElse(Option.scala:121)
at reactivemongo.core.actors.MongoDBSystem$class.reactivemongo$core$actors$MongoDBSystem$$pickChannel(actors.scala:748)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$4.applyOrElse(actors.scala:340)
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:170)
at akka.actor.Actor$class.aroundReceive(Actor.scala:482)
at reactivemongo.core.actors.LegacyDBSystem.aroundReceive(actors.scala:896)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
[error] r.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)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:748)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$reactivemongo$core$actors$MongoDBSystem$$pickChannel$4.apply(actors.scala:748)
at scala.Option.getOrElse(Option.scala:121)
at reactivemongo.core.actors.MongoDBSystem$class.reactivemongo$core$actors$MongoDBSystem$$pickChannel(actors.scala:748)
at reactivemongo.core.actors.MongoDBSystem$$anonfun$4.applyOrElse(actors.scala:340)
at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:170)
at akka.actor.Actor$class.aroundReceive(Actor.scala:482)
at reactivemongo.core.actors.LegacyDBSystem.aroundReceive(actors.scala:896)
at akka.actor.ActorCell.receiveMessage(ActorCell.scala:526)
When I completely kill the process and execute activator run again, everything works like before.
Here's how I use ReactiveMongo:
val collection: Future[JSONCollection] = reactiveMongoApi.database.map(_.collection[JSONCollection](collectionName))
Used versions:
MongoDB: v3.2.4
Scala: 2.11.8
Play 2.5
play2-reactivemongo: 0.11.13
reactivemongo-play-json: 0.11.14
As developing like this takes forever, I would appreciate any help to fix this issue! :-)
I faced this issue as well; every time I reloaded my Play application (including hot reloads), I received hundreds of connection errors. After trying a couple times, my application would run fine until the next reload. This only started happening after I upgraded from ReactiveMongo 0.x to 1.x. I've tried running MongoDB (versions 3.2 through 4.0) locally, as both a native install and in a Docker container.
I "solved" it by adding the following connection options:
MongoConnectionOptions(maxIdleTimeMS = 100000, heartbeatFrequencyMS = 100)
The full connection looks like this:
private val driver = new reactivemongo.api.AsyncDriver
val connection: Future[MongoConnection] = driver.connect(List("localhost"), MongoConnectionOptions(maxIdleTimeMS = 100000, heartbeatFrequencyMS = 100))
I don't know why these values seem to work, or whether they're optimal. And I probably wouldn't recommend running a heartbeat of 100ms in production. However, it's working for my development needs, so I figured I'd share.

Mongodb connection shows inappropriate number on mongo console.

I am using Mongodb 3.2 version. Using Spring's org.springframework.data.mongodb.core.MongoTemplate and com.mongodb.Mongo for mongodb connections, queries and aggregation.
Software Configuration:
spring-core 4.1.6.RELEASE, spring-data-mongodb 1.8.2.RELEASE, mongo-java-driver 3.1.0, spring-context 4.1.6.RELEASE, Tomcat 8.
It looks like mongodb connections are not closing properly. At some time mongodb console shows 10 connections still active. Other than my webapp I use Robomongo tool to check mongodb data. So it should be only two connections at any point of time.
After i shutdown my tomcat and Robomongo, still there are 4 connections active and also at some point it had peaked to 10 with tomcat and Robomongo running.
Logs:
2016-07-16T12:29:12.835+0530 I CONTROL [initandlisten] MongoDB starting : pid=792 port=27017 dbpath=C:\mongodata 64-bit host=DESKTOP-SFNL93Q
2016-07-16T12:29:12.956+0530 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-07-16T12:29:12.960+0530 I CONTROL [initandlisten] db version v3.2.6
2016-07-16T12:29:12.961+0530 I CONTROL [initandlisten] git version: 05552b562c7a0b3143a729aaa0838e558dc49b25
2016-07-16T12:29:12.962+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-07-16T12:29:12.964+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-07-16T12:29:12.965+0530 I CONTROL [initandlisten] modules: none
2016-07-16T12:29:12.966+0530 I CONTROL [initandlisten] build environment:
2016-07-16T12:29:12.967+0530 I CONTROL [initandlisten] distmod: 2008plus-ssl
2016-07-16T12:29:12.968+0530 I CONTROL [initandlisten] distarch: x86_64
2016-07-16T12:29:12.969+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-07-16T12:29:12.970+0530 I CONTROL [initandlisten] options: { storage: { dbPath: "C:\mongodata" } }
2016-07-16T12:29:12.993+0530 I - [initandlisten] Detected data files in C:\mongodata created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2016-07-16T12:29:12.999+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=4G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-07-16T12:29:14.717+0530 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-07-16T12:29:14.717+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/mongodata/diagnostic.data'
2016-07-16T12:29:14.744+0530 I NETWORK [initandlisten] waiting for connections on port 27017
2016-07-16T12:33:51.795+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53065 #1 (1 connection now open)
2016-07-16T12:41:16.247+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53243 #2 (2 connections now open)
2016-07-16T12:41:58.268+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53253 #3 (3 connections now open)
2016-07-16T12:41:58.318+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53254 #4 (4 connections now open)
2016-07-16T12:42:02.864+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53255 #5 (5 connections now open)
2016-07-16T12:42:02.922+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53256 #6 (6 connections now open)
2016-07-16T12:42:04.920+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53257 #7 (7 connections now open)
2016-07-16T12:42:04.958+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53258 #8 (8 connections now open)
2016-07-16T12:46:51.214+0530 I NETWORK [conn1] end connection 127.0.0.1:53065 (7 connections now open)
2016-07-16T12:46:51.216+0530 I NETWORK [conn2] end connection 127.0.0.1:53243 (7 connections now open)
2016-07-16T12:48:51.768+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53378 #9 (7 connections now open)
2016-07-16T12:51:07.622+0530 I NETWORK [conn9] end connection 127.0.0.1:53378 (6 connections now open)
2016-07-16T12:53:27.581+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:53403 #10 (7 connections now open)
2016-07-16T12:54:20.400+0530 I NETWORK [conn3] end connection 127.0.0.1:53253 (6 connections now open)
2016-07-16T12:54:20.401+0530 I NETWORK [conn4] end connection 127.0.0.1:53254 (6 connections now open)
2016-07-16T12:55:38.285+0530 I NETWORK [conn10] end connection 127.0.0.1:53403 (4 connections now open)

Mongodb : I used db.shutdownServer() but connections increased

In my terminal, I used db.shutdownServer() to restart the server.( and I also tried Ctrl+C to terminate.)
but after when I typed "sudo mongod", last connections are still alived and even more increased.
Like this...
0.1:63292 #46 (46 connections now open)
2015-06-23T20:49:25.249+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63293 #47 (47 connections now open)
2015-06-23T20:49:25.250+0900 I NETWORK [conn47] end connection 127.0.0.1:63293 (46 connections now open)
2015-06-23T20:49:25.253+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63294 #48 (47 connections now open)
2015-06-23T20:49:25.254+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63295 #49 (48 connections now open)
2015-06-23T20:49:25.254+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63296 #50 (49 connections now open)
2015-06-23T20:49:25.254+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63297 #51 (50 connections now open)
2015-06-23T20:49:25.254+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63298 #52 (51 connections now open)
2015-06-23T20:49:36.257+0900 I NETWORK [initandlisten] connection accepted from 127.0.0.1:63300 #53 (52 connections now open)
what is the problem?? Please let me know the reason. Thank you !