Skip to content

pgwire: also support cancel under TLS#54618

Merged
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20200921-pgwire-cancel
Sep 22, 2020
Merged

pgwire: also support cancel under TLS#54618
craig[bot] merged 1 commit intocockroachdb:masterfrom
knz:20200921-pgwire-cancel

Conversation

@knz
Copy link
Copy Markdown
Contributor

@knz knz commented Sep 21, 2020

The pg protocol spec says that cancel messages should be sent
unencrypted, prior to authentication and the TLS handshake.

We've seen a report of a user seeing this after TLS in their logs
though. See https://github.com/cockroachlabs/support/issues/600

So this patch extends the code to handle both situations.

Release note (bug fix): CockroachDB now handles PostgreSQL "cancel"
messages on TLS connections in the same way as when they are sent
without TLS: the connection is closed, but no action takes place. No
error is logged. As a reminder, PostgreSQL "cancel" messages are still
unsupported in CockroachDB and client should still use CANCEL QUERY
instead.

The pg protocol spec says that cancel messages should be sent
unencrypted, prior to encryption and the TLS handshake.

We've seen a report of a user seeing this after TLS in their logs
though. So this patch extends the code to handle both situations.

Release note (bug fix): CockroachDB now handles PostgreSQL "cancel"
messages on TLS connections in the same way as when they are sent
without TLS: the connection is closed, but no action takes place. No
error is logged. As a reminder, PostgreSQL "cancel" messages are still
unsupported in CockroachDB and client should still use CANCEL QUERY
instead.
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

Copy link
Copy Markdown
Contributor

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think closing a connection when the client opened it just to send a cancel message (so, in the per-TLS case) is make sense (and regardless of what I think, it is mandated by the docs), but is it also fine in the post-TLS case? Are we doing anybody a favor by closing a connection that was being used by other stuff, instead of just ignoring the message? Is that what pg does?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @andreimatei and @yuzefovich)

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 21, 2020

Is that what pg does?

Yes: the pgwire protocol does not even support a response for a cancel request, and specifies the conn is closed immediately after the query is cancelled.

@andreimatei
Copy link
Copy Markdown
Contributor

LGTM assuming you've actually tested pg.

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 21, 2020

I can't really test pg since psql nor lib/pq does never do this. The only thing I have is the doc...

@andreimatei
Copy link
Copy Markdown
Contributor

Well but that's what I'm saying - the doc only talks about cancel messages sent on brand new connections, not on existing connections. Closing a connection that was opened for this specific purpose is one thing, closing an arbitrary connection is another in my opinion.
Unless we know that pg behaves differently, my preference is to just ignore the message when it comes on an established connection. Which ignoring, btw, is what the protocol tells you to do when the pid in the message is not recognized, so that makes me feel even better about ignoring it.

I think you can test pg with the data-driven pgwire tests that we have, where you can control exactly what messages get sent. I might be wrong...

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 21, 2020

Well but that's what I'm saying - the doc only talks about cancel messages sent on brand new connections, not on existing connections.

You might be misreading my diff? The new condition I added is also on the code path for brand new connections, before authn happens. Does this change your view?

Copy link
Copy Markdown
Contributor

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What new condition? I see that you've extracted a helper function, but otherwise did you change anything about the handling of the cancel message on brand new conns?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @yuzefovich)

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 21, 2020

See the green part at the bottom right here:
image

Copy link
Copy Markdown
Contributor

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rapahel just explained to me that this patch changes the existing behavior a lot less than I thought - it only applies in the initial version-negotiation phase of a conn.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @yuzefovich)

@knz
Copy link
Copy Markdown
Contributor Author

knz commented Sep 22, 2020

thanks

bors r=andreimatei

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 22, 2020

Build succeeded:

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.

3 participants