-
Notifications
You must be signed in to change notification settings - Fork 490
Provide SQLSTATE #814
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
Provide SQLSTATE #814
Conversation
*/ | ||
void disconnect_client(PgSocket *client, bool notify, const char *reason, ...) | ||
{ | ||
usec_t now = get_cached_time(); | ||
|
||
if (reason) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be moved to disconnect_client_sqlstate
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you referring to now
variable? It was moved to disconnect_client_sqlstate
. I checked a few times after reading the diff. diff seems confusing. now
is in line 999.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no I meant the if (reason) {
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code looks good overall. But I think this should include a regression test. Also there's some compilation warning in CI that should be fixed.
Thanks for checking. I noticed the failure after creating this PR. I will fix that error and create a test case for this issue. |
PgBouncer currently uses SQLSTATE 08P01 (protocol_violation) as default error code to send error messages to client. There are cases that this SQLSTATE is different from what Postgres provides. Since the goal is to be as transparent as possible, PgBouncer should report the SQLSTATE provided by Postgres. Issue pgbouncer#778 exposes one case that if you connect to a database that doesn't exist, Postgres reports 3D000 (invalid_catalog_name) but PgBouncer reports 08P01. The npgsql driver relies on the SQLSTATE to check if the database already exists and this behavior breaks it. PgBouncer will use the SQLSTATE that Postgres provides. Fix issue pgbouncer#778.
I tried to come up with a test case but it seems psycopg decided that it doesn't use the Invalid Catalog Name (3D000) for the 'database "foo" does not exist' case. According to psycopg2.errors, class 3D belongs to ProgrammingError exception but a single connection to a database that doesn't exist returns OperationalError exception.
Unless, I'm missing some trick, I think a test case won't be possible. |
All of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I tried to create the test that I had in my mind. But indeed it's not possible. The error code is not exposed to us. And the reason for that is actually because the error result is not exposed to psycopg by libpq.
Did you manually test that this fixes the problem with npgsql? If so, I think we should just merge this. The code looks good, but someone should at least test that this fixes the issue manually.
I manually inspected the messages but didn't give it a try with Npgsql. I pinged the other issue to see if someone tested it or can test it. |
If you manually inspected the result that's good enough for me. I'll press the merge button now. In the unlikely case that people on the issue still reach out that it didn't fix the problem, then it's probably a minor change. |
This reverts commit 084310c.
PgBouncer currently uses SQLSTATE 08P01 (protocol_violation) as default error code to send error messages to client. There are cases that this SQLSTATE is different from what Postgres provides. Since the goal is to be as transparent as possible, PgBouncer should report the SQLSTATE provided by Postgres. Issue #778 exposes one case that if you connect to a database that doesn't exist, Postgres reports 3D000 (invalid_catalog_name) but PgBouncer reports 08P01. The npgsql driver relies on the SQLSTATE to check if the database already exists and this behavior breaks it. PgBouncer will use the SQLSTATE that Postgres provides.
Fix issue #778.