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

srv support in the connection url for sails-mongo #7344

Closed
sereisoglu opened this issue Aug 19, 2024 · 7 comments · Fixed by balderdashy/sails-mongo#501
Closed

srv support in the connection url for sails-mongo #7344

sereisoglu opened this issue Aug 19, 2024 · 7 comments · Fixed by balderdashy/sails-mongo#501

Comments

@sereisoglu
Copy link

Node version:
Sails version (sails): 1.5.11
ORM hook version (sails-hook-orm):
Sockets hook version (sails-hook-sockets):
Organics hook version (sails-hook-organics):
Grunt hook version (sails-hook-grunt):
Uploads hook version (sails-hook-uploads):
DB adapter & version (e.g. [email protected]): sails-mongo 2.1.1
Skipper adapter & version (e.g. [email protected]):
MongoDB version: 6.0


Hello, there is no srv support in the connection url for sails-mongo.

error: A hook (`orm`) failed to load!
error: Could not tear down the ORM hook.  Error details: Error: Consistency violation: Attempting to tear down a datastore (`default`) which is not currently registered with this adapter.  This is usually due to a race condition in userland code (e.g. attempting to tear down the same ORM instance more than once), or it could be due to a bug in this adapter.  (If you get stumped, reach out at http://sailsjs.com/support.)
    at Object.teardown (/Users/sereisoglu/Desktop/test-project/node_modules/sails-mongo/lib/index.js:390:19)
    at /Users/sereisoglu/Desktop/test-project/node_modules/waterline/lib/waterline.js:767:27
    at /Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:3113:16
    at eachOfArrayLike (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:1072:9)
    at eachOf (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:1120:5)
    at Object.eachLimit (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:3175:5)
    at Object.teardown (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/lib/waterline.js:751:11)
    at Hook.teardown (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/index.js:246:30)
    at Sails.wrapper (/Users/sereisoglu/Desktop/test-project/node_modules/@sailshq/lodash/lib/index.js:3305:19)
    at Object.onceWrapper (node:events:632:28)
    at Sails.emit (node:events:518:28)
    at emitter.emit (/Users/sereisoglu/Desktop/test-project/node_modules/sails/lib/app/private/after.js:56:26)
    at /Users/sereisoglu/Desktop/test-project/node_modules/sails/lib/app/lower.js:67:11
    at beforeShutdown (/Users/sereisoglu/Desktop/test-project/node_modules/sails/lib/app/lower.js:45:12)
    at Sails.lower (/Users/sereisoglu/Desktop/test-project/node_modules/sails/lib/app/lower.js:49:3)
    at Sails.wrapper [as lower] (/Users/sereisoglu/Desktop/test-project/node_modules/@sailshq/lodash/lib/index.js:3305:19)
error: Failed to lift app: Error: Invalid configuration for datastore `default`:  Could not process connection url.  Unrecognized option (`appName`) specified in query string of connection URL.
(This adapter expects only standard, whitelisted properties.)
--
See http://sailsjs.com/config/datastores#?the-connection-url for info, or visit
)https://sailsjs.com/support for more help.
--
Please correct this and try again.
(See http://sailsjs.com/config/datastores#?the-connection-url for more info.)
    at Object.registerDatastore (/Users/sereisoglu/Desktop/test-project/node_modules/sails-mongo/lib/index.js:209:58)
    at /Users/sereisoglu/Desktop/test-project/node_modules/waterline/lib/waterline.js:717:27
    at /Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:3113:16
    at eachOfArrayLike (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:1072:9)
    at eachOf (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:1120:5)
    at Object.eachLimit (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/node_modules/async/dist/async.js:3175:5)
    at Object.initialize (/Users/sereisoglu/Desktop/test-project/node_modules/waterline/lib/waterline.js:653:11)
    at buildOntologyAndRunAutoMigrations (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/lib/build-ontology-and-run-auto-migrations.js:55:7)
    at async.auto._buildOntology (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/lib/initialize.js:456:7)
    at runTask (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1635:13)
    at /Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1575:13
    at processQueue (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1585:13)
    at taskComplete (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1604:9)
    at /Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/node_modules/async/dist/async.js:1628:17
    at /Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/node_modules/async/dist/async.js:972:16
    at async.auto._checkAdapterCompatibility (/Users/sereisoglu/Desktop/test-project/node_modules/sails-hook-orm/lib/initialize.js:428:14)

I shared the error message above. It says there is a problem with appName, but appName is found in the connection url with and without srv. It gives this error only for connection url with srv.

Connection url formats:
without srv: (this works with sails-mongo)
mongodb://admin:<password>@clusterName-shard-00-00.xxxxx.mongodb.net:27017,clusterName-shard-00-01.xxxxx.mongodb.net:27017,clusterName-shard-00-02.xxxxx.mongodb.net:27017/database?ssl=true&replicaSet=atlas-xxxxxx-shard-0&authSource=admin&retryWrites=true&w=majority&appName=clusterName

with srv: (this does not work with sails-mongo)
mongodb+srv://admin:<password>@clusterName.xxxxx.mongodb.net/database?retryWrites=true&w=majority&appName=clusterName

@sailsbot
Copy link

@sereisoglu Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

  • look for a workaround. (Even if it's just temporary, sharing your solution can save someone else a lot of time and effort.)
  • tell us why this issue is important to you and your team. What are you trying to accomplish? (Submissions with a little bit of human context tend to be easier to understand and faster to resolve.)
  • make sure you've provided clear instructions on how to reproduce the bug from a clean install.
  • double-check that you've provided all of the requested version and dependency information. (Some of this info might seem irrelevant at first, like which database adapter you're using, but we ask that you include it anyway. Oftentimes an issue is caused by a confluence of unexpected factors, and it can save everybody a ton of time to know all the details up front.)
  • read the code of conduct.
  • if appropriate, ask your business to sponsor your issue. (Open source is our passion, and our core maintainers volunteer many of their nights and weekends working on Sails. But you only get so many nights and weekends in life, and stuff gets done a lot faster when you can work on it during normal daylight hours.)
  • let us know if you are using a 3rd party plugin; whether that's a database adapter, a non-standard view engine, or any other dependency maintained by someone other than our core team. (Besides the name of the 3rd party package, it helps to include the exact version you're using. If you're unsure, check out this list of all the core packages we maintain.)

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

@DominusKelvin
Copy link
Contributor

Thanks @sereisoglu, I'll follow up on this one to see if we can land a PR by the end of the week. cc @eashaw

@Josebaseba
Copy link
Contributor

Hello, I’m here to shed some light on the issue.

Compatibility with the +srv protocol was added years ago; I included it myself in a PR years back.

The problem is with the appName parameter, which needs to be added in the constants file.

Notice that the appname element already exists in the array, but appName in camelCase is missing and needs to be added at the end of the array.

Personally, I wouldn’t delete the lowercase appname because, even though I believe it’s a mistake since it’s never used in lowercase in the connection URL, it is still a variable that exists as an option in the drivers.

I hope it helps.

@DominusKelvin
Copy link
Contributor

Hey @Josebaseba this is very useful and with what you explained I think it will help land a fix for this sooner than I expect. I will submit a patch. In the spirit of making the smallest change to land this, I will add the appName and test if it fixes it then maybe in a separate PR see to remove appname.

@DominusKelvin
Copy link
Contributor

Hey @sereisoglu thanks to @Josebaseba we've discovered this is a whitelist config options issue and I have made a PR to add the appName config option.

@sereisoglu
Copy link
Author

Hey @Josebaseba, @DominusKelvin, as I mentioned above, appName is available in both srv and non-srv urls, but since it only caused problems in srv urls, I thought the problem was that srv support was not available. Thanks for your comment, that was very informative @Josebaseba. Thanks for your PR and support @DominusKelvin.

@DominusKelvin
Copy link
Contributor

Sure thing @sereisoglu!

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

Successfully merging a pull request may close this issue.

4 participants