Skip to content

Remove assumption that the auth response is AuthenticateOk #1188

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yoshihikoueno
Copy link

This PR aims to solve an issue where lib/pq fails to connect to a PostgreSQL cluster via PgPool-II.

Issue description

lib/pq currently assumes the message sent from the server after sending PasswordMessage to be AuthenticationOk.
However, this assumption doesn't always stand as the server may send some other messages other than AuthenticationOk such as another authentication request.

That occurs when lib/pq is trying to connect to a PgPool-II server, where the following procedure is required as PgPool-II wants to have the password in both Cleartext and MD5 formats:

[Client -> Server] StartupMessage
[Server -> Client] AuthenticationCleartextPassword
[Client -> Server] PasswordMessage
[Server -> Client] AuthenticationMD5Password
[Client -> Server] PasswordMessage
[Server -> Client] AuthenticationOk
[Server -> Client] ReadyForQuery

Solution description

Current implementation of auth function of lib/pq will fail if the message after sending credentials is not AuthenticationOk, but we can just return before checking it and let another loop of auth check it instead.
The official client libpq (and of course softwares that use it such as psql and pgAdmin) does support handling multiple authentication requests, thus it can connect to PgPool-II just fine with the procedure above. So making lib/pq check the message sent from the server after PasswordMessage will solve the described issue and align its behavior with the official client.

Thank you for checking out this PR. Please let me know if there's anything that is missing or needs improvements with this PR.

@yoshihikoueno yoshihikoueno force-pushed the feature/support_multi_auth branch from 388e66a to ca66dd0 Compare April 28, 2025 14:47
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

Successfully merging this pull request may close these issues.

1 participant