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

Allow URL encoded host in parseDSN #409

Merged
merged 1 commit into from
Sep 10, 2022

Conversation

mgreenw
Copy link
Contributor

@mgreenw mgreenw commented Sep 10, 2022

This PR allows the connection string host to be url encoded, which is needed for Google Cloud run to connect to the UNIX socket.

When connecting to Google Cloud SQL from Google Cloud Run, the default and recommended way to is to use a provided UNIX socket located at /cloudsql/<project-id>:<region-name>:<sql-instance>. However, to connect to that socket, the host must be provided as a URL-encoded string like %2Fcloudsql%2F<project-id>%3A<region-name>%3Ar<sql-instance>. Before slonik@25.1.0, this worked properly because the connection URI was passed directly to pg. However, the new parseDSN util no longer url-decodes the host before passing it in to pg, meaning that these url-encoded sockets will stay encoded and cannot be understood by pg, resulting in an "Address Not Found" warning.

To fix this, this PR calls decodeURICompenent on the hostname before it is assigned to host. This should not cause any issues with existing urls that had no url-unsafe characters, and will allow users of GCP to connect from cloud run to cloud sql without needing to do additional setup to connect via TCP.

I have tested this in a live Google Cloud Run instance and it works great! @gajus Please let me know if I'm missing anything here.

@mgreenw mgreenw temporarily deployed to release September 10, 2022 17:15 Inactive
@mgreenw mgreenw temporarily deployed to release September 10, 2022 17:15 Inactive
@mgreenw mgreenw temporarily deployed to release September 10, 2022 17:15 Inactive
@mgreenw mgreenw temporarily deployed to release September 10, 2022 17:15 Inactive
@mgreenw mgreenw temporarily deployed to release September 10, 2022 17:15 Inactive
@gajus gajus merged commit d66b76c into gajus:main Sep 10, 2022
@github-actions
Copy link
Contributor

🎉 This PR is included in version 31.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

None yet

2 participants