I have a nodejs app which is doing some mongodb database migration.
All of it starts with
MongoClient.connect(`mongodb://${databaseHostname}:${databasePort}/${options.databaseName}`,
(connectionError, dbConnection) => {
if (connectionError) {
return cb(connectionError);
}
console.log('Opened connection to', databaseHostname, options.databaseName);
return cb(null, dbConnection);
});
And ends with
console.log('Close');
dbConnection.close((err) => {
if (err) console.log(err);
console.log('Closed');
});
In between there is quite a lot happening, new collections created, documents rearranged etc. But never a new connection opened. The output of the app is:
Opened connection to localhost testDatabase
[Lots of other logs here]
Close
Closed
The database logs are
2016-07-18T16:54:29.400+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:54336 #848 (1 connection now open)
2016-07-18T16:54:29.423+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:54337 #849 (2 connections now open)
2016-07-18T16:54:29.426+0200 I NETWORK [initandlisten] connection accepted from 127.0.0.1:54338 #850 (3 connections now open)
[Lots of insertions and updates here]
2016-07-18T16:58:06.493+0200 I NETWORK [conn849] end connection 127.0.0.1:54337 (2 connections now open)
2016-07-18T16:58:06.494+0200 I NETWORK [conn850] end connection 127.0.0.1:54338 (1 connection now open)
As you can see, one mongodb connection stays open even though dbConnection.close() got called preventing the nodejs app to exit. I am looking at this for quite some time now but do not understand what could cause this behaviour?