balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.84k stars 1.95k forks source link

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

Closed sereisoglu closed 1 month ago

sereisoglu commented 2 months ago

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. sails-mysql@5.55.5): sails-mongo 2.1.1 Skipper adapter & version (e.g. skipper-s3@5.55.5): 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 commented 2 months ago

@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:

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

Sure thing @sereisoglu!