Skip to content

No reconnection after PRIMARY down if there is a model.watch #6741

Description

@majordo

I am using mongoose@5.2.4 with a replicaSet of 3 nodes with mongo v3.6.2.
Node v8.11.2
Do you want to request a feature or report a bug? BUG

I noticed that reconnection does not work if there is a model.watch.
If I enable model.watch and turn off the PRIMARY I get this error:

.../node_modules/mongodb/lib/utils.js:132
      throw err;
      ^
MongoNetworkError: connection 6 to 192.168.0.1:27017 closed

If there are no model.watch there are no errors and my application normally reconnects after the election of the PRIMARY node.

If the current behavior is a bug, please provide the steps to reproduce.

import mongoose from "mongoose";
const uri="mongodb://192.168.0.1:27017,192.168.0.2:27017,192.168.0.3:27017/test?replicaSet=test"
mongoose.connect(config.mongodb.uri, {
    useNewUrlParser: true,
});
const mongoDB = mongoose.connection;
mongoDB
    .on('connecting', () => console.log('connecting to MongoDB...'))
    .on('connected', () => console.log('MongoDB connected...'))
    .on('reconnected', () => console.log('MongoDB reconnected!'))
    .on('disconnecting', () => console.log('MongoDB disconnecting...'))
    .on('timeout', (e) => console.log('MongoDB timeout ->', e))
    .on('disconnected', () => console.log('MongoDB disconnected'))
    .on('error', () => {
         mongoose.disconnect();
         console.log('Failed to connect to MongoDB.')
    })
    .once('open', () => console.log('MongoDB connection opened! DONE!'))


// userModel
//     .watch(null, { fullDocument: "updateLookup" })
//     .on("change", change => {
//         console.warn('USER CHANGE:', change)
//     })

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    underlying library issueThis issue is a bug with an underlying library, like the MongoDB driver or mongodb-core

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions