MongoDB - The connection is not disconnected for a long time I am building a system that outputs information such as visit information and page transition of the user who visited the website to MongoDB, The MongoDB connection pool of the server of the web site became MAX and it ceased to MongoDB from the web site.

The MongoDB service is configured with the following configuration.

mongos server#1 service：mongos、config mongos server#2 service：mongos、config、rs01arbiter mongos server#3 service：mongos、config、rs02arbiter node#1 service：rs01(secondary)、rs02(secondary) node#2 service：rs01(primary)、rs02(primary)

※Originally the following state is set, but OS is restarted, primary has dropped to node # 2, but it is left as it is node#1 service：rs01(primary)、rs02(secondary) node#2 service：rs01(secondary)、rs02(primary)

From this state, we restarted the OS of node # 2. rs 01 and rs 02 of node # 1 were promoted to primary. rs01, rs02 of node # 2 demoted to secondary.I confirmed it from the log.

However, it happened that more connections would take more than 1 to 2 hours from OS reboot on node # 2 to expire. And the MongoDB connection pool of the server of the web site became MAX and it became not connected to MongoDB from the web site. Normally it will be out of connection in about 30 minutes at the longest. I thought that node # 1 works as Primary, so I thought it would work normally, but I do not know why the connection is not disconnected for a long time.

If you encounter similar events, please let me know if anyone knows the solution or workaround.

appendix
The version of MongoDB is "MongoDB 3.0.12". The application connected to MongoDB is built with .net c # and is running on Windows Server 2012 R2. TCP Keepalive remains the default setting. Also when connecting from application socketOptions.keepAlive has not changed. The connectionString of the application also does not set the option as follows.
From this state, we restarted the OS of node # 2. rs 01 and rs 02 of
  node # 1 were promoted to primary. rs01, rs02 of node # 2 demoted to
  secondary.I confirmed it from the log.
  
  However, it happened that more connections would take more than 1 to 2
  hours from OS reboot on node # 2 to expire. And the MongoDB connection
  pool of the server of the web site became MAX and it became not
  connected to MongoDB from the web site. Normally it will be out of
  connection in about 30 minutes at the longest. I thought that node # 1
  works as Primary, so I thought it would work normally, but I do not
  know why the connection is not disconnected for a long time.


As per MongoDB documentation here The priority settings of replica set members affect both the timing and the outcome of elections for primary. Higher-priority members are more likely to call elections, and are more likely to win. Use this setting to ensure that some members are more likely to become primary and that others can never become primary.

The value of the member’s priority setting determines the member’s priority in elections. The higher the number, the higher the priority.


  Note:
  As you said that the version 3.0, this version of the manual is no longer supported. Learn
  more about upgrading your version of MongoDB.


For further your ref here and here