所以我有一套黄瓜测试,在BeforeFeatures
部分我在同一台服务器上创建了与2个数据库的连接,我已经将池设置为2,所以我可以看到连接4个连接时(2)有2个池的数据库。)
然后在最后我关闭数据库,如下:
var closeDatabase = function(callback) {
db1.close(function(){
db2.close(function(){
console.log("DONE");
callback();
});
});
};
现在调用它,我看到控制台输出和进程关闭,因此应该关闭两个数据库连接。但是如果我看一下mongodb日志:
2016-01-14T11:45:05.813+0000 [initandlisten] MongoDB starting : pid=888 port=27017 dbpath=C:\Tools\mongodb\data 64-bit host=SomePC
2016-01-14T11:45:05.818+0000 [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-01-14T11:45:05.821+0000 [initandlisten] db version v2.6.7
2016-01-14T11:45:05.822+0000 [initandlisten] git version: a7d57ad27c382de82e9cb93bf983a80fd9ac9899
2016-01-14T11:45:05.826+0000 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1') BOOST_LIB_VERSION=1_49
2016-01-14T11:45:05.829+0000 [initandlisten] allocator: system
2016-01-14T11:45:05.830+0000 [initandlisten] options: { storage: { dbPath: "C:\Tools\mongodb\data" } }
2016-01-14T11:45:05.846+0000 [initandlisten] journal dir=C:\Tools\mongodb\data\journal
2016-01-14T11:45:05.848+0000 [initandlisten] recover : no journal files present, no recovery needed
2016-01-14T11:45:05.871+0000 [initandlisten] waiting for connections on port 27017
2016-01-14T11:45:11.639+0000 [initandlisten] connection accepted from 127.0.0.1:51841 #1 (1 connection now open)
2016-01-14T11:45:11.646+0000 [conn1] end connection 127.0.0.1:51841 (0 connections now open)
2016-01-14T11:45:11.650+0000 [initandlisten] connection accepted from 127.0.0.1:51842 #2 (1 connection now open)
2016-01-14T11:45:11.653+0000 [initandlisten] connection accepted from 127.0.0.1:51843 #3 (2 connections now open)
2016-01-14T11:45:11.659+0000 [initandlisten] connection accepted from 127.0.0.1:51844 #4 (3 connections now open)
2016-01-14T11:45:11.662+0000 [conn4] end connection 127.0.0.1:51844 (2 connections now open)
2016-01-14T11:45:11.665+0000 [initandlisten] connection accepted from 127.0.0.1:51845 #5 (3 connections now open)
2016-01-14T11:45:11.669+0000 [initandlisten] connection accepted from 127.0.0.1:51846 #6 (4 connections now open)
2016-01-14T11:45:11.689+0000 [conn5] end connection 127.0.0.1:51845 (3 connections now open)
2016-01-14T11:45:11.689+0000 [conn6] end connection 127.0.0.1:51846 (3 connections now open)
2016-01-14T11:45:11.690+0000 [conn2] end connection 127.0.0.1:51842 (3 connections now open)
2016-01-14T11:45:11.690+0000 [conn3] end connection 127.0.0.1:51843 (3 connections now open)
所以最后虽然2个连接已经结束,但似乎让4个连接中的3个处于活动状态。这就是说,如果我们看看端口,它似乎激活6个端口,即使它只有4个连接。
这是常见的吗?我应该担心还是我做错了什么?这是一个问题的全部原因是因为当我尝试使用连接时,我得到错误:
MongoError: server localhost:27017 sockets closed
所以当我尝试使用连接时,为什么它看似过度分配和轰炸我感到有些困惑。
答案 0 :(得分:0)
所以错误是正确的,它正在关闭连接然后使用它们,因为它们的方式控制台输出发生在Windows上,它们并不总是100%正确的顺序。事实证明,黄瓜在一个地区默默地轰炸,并在这里发挥作用。