-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 3.3.3
-
Component/s: None
-
Environment:NodeJS Version: 12.10.0
OS Version: macOS 10.15
When trying to connect to a server that is offline it is throwing a unhandled error instead of it being caught in the promise.catch.
import { MongoClient } from "mongodb"; // Connection URL const url = "<<PUT_URL_HERE>>"; const connect = async () => { const client = new MongoClient(url, { useNewUrlParser: true, useUnifiedTopology: true }); await client.connect(); await client.close(); }; connect().then(() => console.log("ALL DONE")).catch((err) => console.error(err));
Error [ERR_STREAM_WRITE_AFTER_END]: write after end at writeAfterEnd (_stream_writable.js:250:14) at Socket.Writable.write (_stream_writable.js:299:5) at Connection.write (/Users/grahamclifford/Documents/git/Other/mongooseTest/node_modules/mongodb/lib/core/connection/connection.js:256:21) at runCommand (/Users/grahamclifford/Documents/git/Other/mongooseTest/node_modules/mongodb/lib/core/connection/connect.js:340:8) at performInitialHandshake (/Users/grahamclifford/Documents/git/Other/mongooseTest/node_modules/mongodb/lib/core/connection/connect.js:127:3) at /Users/grahamclifford/Documents/git/Other/mongooseTest/node_modules/mongodb/lib/core/connection/connect.js:43:9 at callback (/Users/grahamclifford/Documents/git/Other/mongooseTest/node_modules/mongodb/lib/core/connection/connect.js:261:5) at Socket.connectHandler (/Users/grahamclifford/Documents/git/Other/mongooseTest/node_modules/mongodb/lib/core/connection/connect.js:297:5) at Object.onceWrapper (events.js:298:28) at Socket.emit (events.js:209:13) Emitted 'error' event on Socket instance at: at errorOrDestroy (internal/streams/destroy.js:107:12) at writeAfterEnd (_stream_writable.js:252:3) at Socket.Writable.write (_stream_writable.js:299:5) [... lines matching original stack trace ...] at Object.onceWrapper (events.js:298:28)
How I came across this was when using Mongoose, if mongo server instance wne don't, it was crashing the process, instead of mongoose trying to reconnect. After narrowing it down it looks to be the Mongo driver that is causing it.