-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
sql: ensure that a pgwire-level cancellation request (using a cancel msg) prevents a client freeze #32973
Comments
@knz could you triage? |
@mjibson what do you think? Is this just driver-side or is there anything to do on our end? |
I just checked it with Postgres and it didn't reproduce. |
Can you try with https://github.com/jackc/pgx? I'm doubtful this is a cockroach bug. We already don't support the cancel protocol (which isn't a bug, we don't currently intend to support it) and I'm curious if something is waiting for a timeout there. |
@mjibson I can't reproduce it with |
Did you use pgx directly or via database/sql? database/sql and lib/pq may be interacting in broken ways. |
All tests are via database/sql. That's stacktraces from
Probably, Cockroach doesn't handle it properly. |
@chessman thanks for the additional information. As noted above, CockroachDb does not support the cancel protocol, however it does cancel a query if the connection gets closed. This will also achieve the desired effect. |
|
Yes that seems reasonable. |
@mjibson even though we may not support the pg cancel protocol, do you see any way we can detect when it is received while a query is running? And respond with an error immediately? I'm not sure. Maybe @andreimatei you have an opinion about this too? |
We should be able to do this with a similar strategy that we were just playing with in #33174. We can change the implementation of |
The cancel signal is sent by drivers on new connections, not the connection processing the query being cancelled. These dedicated connections are identified from the get-go; the docs say:
So it seems that we should just close connections when a |
The cancel docs also state that
Implying that we shouldn't even return a "not implemented" error. There are unsolved problems when dealing with the cancel protocol:
Answering these questions isn't currently on the roadmap, so I'm not sure anything will move here soon. |
@mjibson we can close the connection upon receiving a cancel message and not do anything else. |
(except bumping a telemetry counter, that is) |
Yes, we should be doing that. If we aren't that's pretty surprising. Confirmed that psql also hangs when you run pg_sleep and hit ^C, which should do that. |
@mjibson could you casually investigate what the current situation is in the code? ie what cockroachdb does/says wyhen it receives a cancel msg? Depending on the specific current situation maybe we can do something about it. |
I agree. I will do that. |
33202: pgwire: detect, log, and immediately close any cancel requests r=mjibson a=mjibson Previously the cmuxer would not detect pgwire cancel requests as pgwire and instead hand them off to GRPC causing them to hang. We still don't support cancel, but it should be handled better by clients now. Fixes #32973 Release note (bug fix): Cancel requests (via the pgwire protocol) will now close quickly with an EOF instead of hang (but still don't cancel the request). Co-authored-by: Matt Jibson <[email protected]>
Issue summary (Added @knz 2018-12-14)
The client tries to cancel its request with a pg cancel message and then gets stuck (until a timeout of 2mn) because the server does not respond. Instead CockroachDB should see the pg cancel message and immediately return an error packet and/or close the connection.
Describe the problem
The request will be terminated exactly in 2 minutes.
To Reproduce
Expected behavior
The request should be terminated immediately after the context is canceled.
Environment:
The text was updated successfully, but these errors were encountered: