-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
When reviewing the behaviour of a NodeJs application compared to a similar Ruby application, the number of connections opened by the drivers do not match.
The following example (using the 3.2.4 node driver) opens 11 connections to each replica set member (10 + 1 monitoring):
const MongoClient = require('mongodb').MongoClient const dbName = 'test' const collectionName = 'coll' let client, db, collection connect = async () => { try { client = await MongoClient.connect('mongodb://localhost:27017,localhost:27018,localhost:27019/test?replicaset=replset&socketTimeoutMS=20000' || process.env.MONGO_URI, { useNewUrlParser: true, forceServerObjectId: true, minSize: 10, poolSize: 20 }) db = client.db(dbName) collection = db.collection(collectionName) setTimeout(() => { client.close() }, 10000) client.on('timeout', (x)=> { console.log(x) }) } catch (err) { console.error(err) } } connect()
A similar program written in Ruby (using the 2.8.0 driver) only opens 2 connections to the PRIMARY and 1 to each SECONDARY:
require 'bundler/inline' gemfile do ruby '2.5.3' source 'https://rubygems.org' gem 'mongo', '2.8.0' end require 'mongo' hosts = [ 'localhost:27017', 'localhost:27018', 'localhost:27019' ] options = { min_pool_size: 10, max_pool_size: 20, max_idle_time: 5 } connection = Mongo::Client.new(hosts, options)["test"] connection.find_one_and_update({ _id: BSON::ObjectId.new }, { message: 'message' }, upsert: true) sleep 5 puts "done"
This doesn't seem to follow the specification:
If minPoolSize is set, the pool MUST immediately create enough connections such that totalConnections >= minPoolSize.
The driver appears to have a method in place to populate the min size of connections but this is only used by the spec runner; not the driver itself.
Notes:
- Tested with both :min_pool_size and :min_size
- Connection "watching" was done via the following script:
#!/bin/bash lsof -i tcp:27017-27019 | grep ESTABLISHED | grep -v mongod | awk '{print $9}' | cut -d'>' -f2 | grep -E "(27017|27018|27019)" | sort | uniq -c
- duplicates
-
RUBY-1605 Establish working connections in a background thread
- Closed