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

--connection-url doesn't handle URI-encoded password #436

Open
keithlayne opened this issue Mar 5, 2025 · 2 comments
Open

--connection-url doesn't handle URI-encoded password #436

keithlayne opened this issue Mar 5, 2025 · 2 comments

Comments

@keithlayne
Copy link

Looks like here:

que/lib/que/locker.rb

Lines 147 to 156 in 17fb2c3

uri = URI.parse(connection_url)
opts =
{
host: uri.host,
user: uri.user,
password: uri.password,
port: uri.port || 5432,
dbname: uri.path[1..-1],
}

I'm trying to use this arg for the first time, and I end up getting a password failure. Is there another way I can provide this option? PG urls allow escaping special chars in the password, and this isn't working.

Actually, with a little experimentation, it really looks like PG::Connection.open is fully capable of parsing connection strings, without the URI.parse step. It appears that it handles both postgres:// URLs and connection strings like user=... password=... host=... dbname=....

So, AFAICT, the connection url option ought to be passed directly to PG::Connection.open.

I do see this, but I don't understand what it's for (I will check the docs):

que/lib/que/locker.rb

Lines 189 to 194 in 17fb2c3

unless connection_args.has_key?(:application_name)
@connection.execute(
"SELECT set_config('application_name', $1, false)",
["Que Locker: #{@connection.backend_pid}"]
)
end

@keithlayne
Copy link
Author

If that's not a good idea for whatever reason, it seems reasonable to do:

password: URI.decode_uri_component(uri.password)

I guess it's conceivable that some other bit of the URL could be encoded, but I've never actually seen that in practice.

@keithlayne
Copy link
Author

My motivation for using this feature was adding pgBouncer. With the tiny patch above I've had no problems for the last couple of weeks.

This repo seems to be in fairly low-frequency maintenance mode, which is fine. If/when somebody gets a chance to look at this, let me know. The change I needed to get this working was trivial, and I would love to get this upstreamed, or have my issue addressed in another way.

I'm happy to PR this if you want, I haven't looked at how tests are set up but hopefully there's an easy way to set up a user with a password that would exercise this. I'll hold off for now in case it's not the desired approach.

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