Repository navigation
pgconn: do not send cancel request without BackendKeyData - #2727
Open
tony1233200 wants to merge 1 commit into
Open
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2726.
When a server completes startup without sending
BackendKeyData,pgConn.secretKeyis empty and a cancel request cannot match anything on the server: the server matches a cancel by PID and secret key, and under protocol 3.0 a cancel request is exactly 16 bytes.CancelRequeststill dialled the server and sent a 12-byte, key-less message, andasyncClosedid the same on every interrupted query of such a connection.CancelRequestnow returns an error (no cancel key: server sent no BackendKeyData) before dialling when no secret key was received.asyncCloseonly sends the cancel request when a key is present, extending thesendCancelRequestgate added by pgconn: do not send cancel request when connect fails #2715 for connections still starting up.A connection to a server that does send
BackendKeyData, as PostgreSQL always does, is unaffected. The new testTestNoCancelRequestWithoutBackendKeyDatamirrorsTestConnectFailureDoesNotSendCancelRequest: a fake server completes startup withoutBackendKeyData, then the test asserts an explicitCancelRequestfails without a second dial, and that an interrupted query goes throughasyncClosewithout one either. The test fails on the parent commit (the explicit cancel dials the server) and passes with this change.