-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.2.0
-
Component/s: Core
-
Environment:Node.js version 8.16.0
Ubuntu Linux 18.04
-
Empty show more show less
Since mongodb-core 3.2.0, connection failure on first connect no longer throws a MongoNetworkError. Instead, an unwrapped error from TCPConnectWrap is thrown.
How to recreate:
- Create a new Node.js project. Then, install mongodb-core 3.2.0.
- Add this code to index.js:
var Server = require('mongodb-core').Server var server = new Server({ host: 'localhost' , port: 27017 , reconnect: true , reconnectInterval: 50 }); server.connect();
(This code is actually straight from the documentation.)
- Make sure no server is listening on that port, then run node index.js
Expected result: Node stops with MongoNetworkError, as it was on mongodb-core 3.1
Actual result: Node stops with the following error:events.js:183 throw er; // Unhandled 'error' event ^ Error: connect ECONNREFUSED 127.0.0.1:27017 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)
For reference, this is how the error looks like on mongodb-core 3.1.11 (the lastest version on 3.1 line):
events.js:183 throw er; // Unhandled 'error' event ^ MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017] at Pool.<anonymous> (<project dir>/node_modules/mongodb-core/lib/topologies/server.js:564:11) at emitOne (events.js:116:13) at Pool.emit (events.js:211:7) at Connection.<anonymous> (<project dir>/node_modules/mongodb-core/lib/connection/pool.js:317:12) at Object.onceWrapper (events.js:317:30) at emitTwo (events.js:126:13) at Connection.emit (events.js:214:7) at Socket.<anonymous> (<project dir>/node_modules/mongodb-core/lib/connection/connection.js:246:50) at Object.onceWrapper (events.js:315:30) at emitOne (events.js:116:13)