Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnection issue #3583

Closed
boysmovie opened this issue Nov 18, 2015 · 5 comments
Closed

Reconnection issue #3583

boysmovie opened this issue Nov 18, 2015 · 5 comments

Comments

@boysmovie
Copy link

I have mongodb setup as standalone server. I also have replicaset enabled as standalone for enabling the oplog (my app tracks realtime updates).

When mongod service is stopped and restarted mongoose auto-reconnects but throws an error when performing write operation. (I understand mongodb cannot write to secondary but I just have one node which is PRIMARY but mongoose thinks its secondary?

d:\project\node_modules\mongoose\node_modules\mongodb\lib\mongodb\db.js:18
67
if(!connection.isCompatible()) {
^
TypeError: Object Error: Cannot write to a secondary has no method 'isCompatible

@vkarpov15
Copy link
Collaborator

When the mongod restarts, it can take a few seconds for it to realize that it's a primary. Is this error a temporary condition or does it persist?

@boysmovie
Copy link
Author

@vkarpov15 - From what I am noticing, after mongod restarts, if the next write request happens after 4 to 5 seconds, I do NOT see this crash. But if the next write request happens very soon within a second or so - crash!

My webapp has heavy traffic load which means the next write op can happen within a second.

To further this question:

  1. I have mongoose on-error event. Why doesn't mongoose call this event rather it crashes the app?

    // If the connection throws an error
    mongoose.connection.on('error',function (err) {
    console.log('MongoDB error!');
    });

  2. When mongoose re-connects, can't it connect only to a node that mongod has made it the PRIMARY?

@vkarpov15
Copy link
Collaborator

Also, which version of mongoose are you using? This looks like an old version.

@boysmovie
Copy link
Author

@vkarpov15 I am on version 3.8.9

@vkarpov15
Copy link
Collaborator

I remember there being some related issues fixed in subsequent 3.8 releases. Could you upgrade to 3.8.37 and see if the issue still happens?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants