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

App silently connects to local test database when the remote url contains un-encoded characters #208

Open
sagrawal31 opened this issue Apr 7, 2021 · 0 comments

Comments

@sagrawal31
Copy link

sagrawal31 commented Apr 7, 2021

Thanks to @AbhishekTaparia for finding out the issue 👏🏻

Environment

  • Grails 4.0.4
  • GORM 7.0.6
  • GORM MongoDB 7.0.1

Problem

We were recently trying to connect to a remote MongoDB instance (hosted on MongoDB Atlas) and we configured the app with the following config in application.groovy (shows fake credentials)-

String mongoDBUsername = "root"
String mongoDBPassword = "67ERH@45hu12"
String mongoDBName = "myFirstDatabase"
String mongoDBHost = "example-development.garhn.mongodb.net"

grails {
    mongodb {
        url = "mongodb+srv://${mongoDBUsername}:${mongoDBPassword}@${mongoDBHost}/${mongoDBName}?retryWrites" +
                "=true&w=majority"
    }
}

When we ran the app using ./gradlew bootRun the app started properly and a few domain instances created properly (which we defined in Bootstrap.groovy). But when we got to see in the MongoDB Atlas (both using their console and mongo shell, we were not finding the collection and any document created.

After 4-5 hours of debugging, we got to know that somehow the Grails is skipping the configuration and connecting to the local instance of MongoDB with test database.

Further investigation leads us to the solution that since the password was having @, it needs to be URL encoded-

String mongoDBPassword = URLEncoder.encode("67ERH@45hu12", "UTF-8")

So when we changed our line as above, the app connected properly to the remote MongoDB host.

Actual Behaviour

The app silently ignores the error and connects to the test database in local MongoDB instance.

Expected Behaviour

The app startup should fail and correct errors should be shown.

Demo application- https://github.com/AbhishekTaparia/test-grails-mongo-issue

Additional Info 1

After upgrading Grails to 4.0.9 to and GORM to 7.0.8, the silent connection to the database does not work instead the app startup freezes and the app never bootstraps.

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

1 participant