Skip to content

readPreference secondaryPreferred causes "Unable to create case insensitive username index: not master" #7048

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

Closed
4 tasks done
sunshineo opened this issue Dec 7, 2020 · 10 comments
Labels
type:bug Impaired feature or lacking behavior that is likely assumed

Comments

@sunshineo
Copy link
Contributor

New Issue Checklist

Issue Description

When Mongo URI has readPreference set to secondaryPreferred (and connecting to a Mongo Atlas cluster) we get the following error:

[13973] parse-server running on http://localhost:1337/parse
warn: Unable to create case insensitive username index:  not master {"operationTime":"6903658739996295169","ok":0,"code":10107,"codeName":"NotMaster","$clusterTime":{"clusterTime":"6903658739996295169","signature":{"hash":"/wM8w3Ym3vb446s04YZqDHx5TTw=","keyId":"6847700517334810656"}},"name":"MongoError","stack":"MongoError: not master\n    at MessageStream.messageHandler (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/connection.js:268:20)\n    at MessageStream.emit (events.js:314:20)\n    at MessageStream.EventEmitter.emit (domain.js:486:12)\n    at processIncomingData (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)\n    at MessageStream._write (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)\n    at writeOrBuffer (_stream_writable.js:352:12)\n    at MessageStream.Writable.write (_stream_writable.js:303:10)\n    at TLSSocket.ondata (_stream_readable.js:717:22)\n    at TLSSocket.emit (events.js:314:20)\n    at TLSSocket.EventEmitter.emit (domain.js:486:12)"}
MongoError: not master
    at MessageStream.messageHandler (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/connection.js:268:20)
    at MessageStream.emit (events.js:314:20)
    at MessageStream.EventEmitter.emit (domain.js:486:12)
    at processIncomingData (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (_stream_writable.js:352:12)
    at MessageStream.Writable.write (_stream_writable.js:303:10)
    at TLSSocket.ondata (_stream_readable.js:717:22)
    at TLSSocket.emit (events.js:314:20)
    at TLSSocket.EventEmitter.emit (domain.js:486:12) {
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1607383308 },
  ok: 0,
  code: 10107,
  codeName: 'NotMaster',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1607383308 },
    signature: { hash: [Binary], keyId: [Long] }
  },
  [Symbol(errorLabels)]: Set(1) { 'RetryableWriteError' }
}

Steps to reproduce

Create a cluster with 3 nodes on MongoDB Atlas. I feel a cluster anywhere can reproduce

// This works
parse-server --appId myappid --masterKey masterkey --databaseURI "mongodb+srv:/<username>:<password>@cluster0.b2mxc.mongodb.net/<db-name>?retryWrites=true&w=3"

// Add &readPreference=secondaryPreferred&slaveOk=true to the end of the URI fails
parse-server --appId myappid --masterKey masterkey --databaseURI "mongodb+srv:/<username>:<password>@cluster0.b2mxc.mongodb.net/<db-name>?retryWrites=true&w=3&readPreference=secondaryPreferred&slaveOk=true"

Environment

Server

  • Parse Server version: 4.4.0
  • Operating system: Mac

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 4.2.10
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): MongoDB Atlas

Logs

[13973] parse-server running on http://localhost:1337/parse
warn: Unable to create case insensitive username index:  not master {"operationTime":"6903658739996295169","ok":0,"code":10107,"codeName":"NotMaster","$clusterTime":{"clusterTime":"6903658739996295169","signature":{"hash":"/wM8w3Ym3vb446s04YZqDHx5TTw=","keyId":"6847700517334810656"}},"name":"MongoError","stack":"MongoError: not master\n    at MessageStream.messageHandler (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/connection.js:268:20)\n    at MessageStream.emit (events.js:314:20)\n    at MessageStream.EventEmitter.emit (domain.js:486:12)\n    at processIncomingData (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)\n    at MessageStream._write (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)\n    at writeOrBuffer (_stream_writable.js:352:12)\n    at MessageStream.Writable.write (_stream_writable.js:303:10)\n    at TLSSocket.ondata (_stream_readable.js:717:22)\n    at TLSSocket.emit (events.js:314:20)\n    at TLSSocket.EventEmitter.emit (domain.js:486:12)"}
MongoError: not master
    at MessageStream.messageHandler (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/connection.js:268:20)
    at MessageStream.emit (events.js:314:20)
    at MessageStream.EventEmitter.emit (domain.js:486:12)
    at processIncomingData (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
    at MessageStream._write (/usr/local/lib/node_modules/parse-server/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
    at writeOrBuffer (_stream_writable.js:352:12)
    at MessageStream.Writable.write (_stream_writable.js:303:10)
    at TLSSocket.ondata (_stream_readable.js:717:22)
    at TLSSocket.emit (events.js:314:20)
    at TLSSocket.EventEmitter.emit (domain.js:486:12) {
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1607383308 },
  ok: 0,
  code: 10107,
  codeName: 'NotMaster',
  '$clusterTime': {
    clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1607383308 },
    signature: { hash: [Binary], keyId: [Long] }
  },
  [Symbol(errorLabels)]: Set(1) { 'RetryableWriteError' }
}
@dplewis
Copy link
Member

dplewis commented Dec 9, 2020

I believe this has been fixed in the latest version of the mongo driver.

https://jira.mongodb.org/browse/NODE-2784

We are looking into updating the driver.

@mtrezza mtrezza added type:bug Impaired feature or lacking behavior that is likely assumed on hold and removed needs more info labels Dec 9, 2020
@mtrezza
Copy link
Member

mtrezza commented Dec 9, 2020

Here are some workaround suggestions:

  • Remove the readPreference from the connection string and instead set it in the Parse Server configuration as driver option. Untested.
  • Set the readPreference as option of the Parse Query where you want to override the driver / connection string read preference. Untested.
  • Manually create the index in the DB.

@sunshineo
Copy link
Contributor Author

sunshineo commented Dec 9, 2020 via email

@sunshineo
Copy link
Contributor Author

@mtrezza manually create the index in the DB does not work. As a matter of fact, when I test removed the readPrefrence settings, it worked and created the index. But when add back the readPreference, code probably is trying to ensure index exists and still fails even the index is already there

this.adapter.ensureIndex(

@mtrezza
Copy link
Member

mtrezza commented Dec 9, 2020

manually create the index in the DB does not work.

I cannot reproduce this with an existing Parse Server deployment by adding readPreference=secondaryPreferred to the connection string. The server works just fine.

@sunshineo
Copy link
Contributor Author

@mtrezza is your DB a cluster with 3 nodes (mine on MongoDB Atlas)?

@mtrezza
Copy link
Member

mtrezza commented Dec 10, 2020

Yes, I tried it with a 3 node (PSS) replica set. Just to be sure I also tried to use the exactly same connection string parameters as yours, still works. Maybe you want to post the created index?

You could also try to upgrade the Parse Server mongodb dependency to 3.6.3.

@sunshineo
Copy link
Contributor Author

Upgrade to 3.6.3 definitely works. I guess I have to install from my repo for a while. I'm creating a PR

@mtrezza
Copy link
Member

mtrezza commented Dec 10, 2020

I reopened the issue because it still exists and the PR has not been merged yet.

@dplewis
Copy link
Member

dplewis commented Dec 10, 2020

Closing via #7026

@dplewis dplewis closed this as completed Dec 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Impaired feature or lacking behavior that is likely assumed
Projects
None yet
Development

No branches or pull requests

3 participants