Skip to content
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

Support cancellation in synchronous client #531

Merged
merged 1 commit into from Dec 31, 2019

Conversation

@benesch
Copy link
Contributor

@benesch benesch commented Dec 25, 2019

The tl;dr is that it'd be nice to be able to send cancellation requests when using the synchronous client. This is a first pass at implementing that. Not sure if it's mergeable in its current form, as it relies on exposing some private bits of tokio-postgres for the sole use of the postgres crate, and then marking those bits as doc(hidden).

@benesch benesch force-pushed the benesch:synchronous-cancel branch from 8cceb77 to 2f53ac7 Dec 26, 2019
@@ -451,6 +450,18 @@ impl Client {
Ok(Transaction::new(self))
}

/// Not part of the public API of this crate.
#[doc(hidden)]
pub fn cancel_token(&self) -> CancelToken {

This comment has been minimized.

@sfackler

sfackler Dec 27, 2019
Owner

I've tried to avoid having private APIs in tokio-postgres just for postgres's sake. I think it's reasonable for this to just be a public API though. I wonder if we should just deprecate cancel_query and cancel_query_raw?

This comment has been minimized.

@benesch

benesch Dec 27, 2019
Author Contributor

That certainly works for me, if it works for you! The only potential downside is that the current (async-only) API can guarantee at compile time that the connection you're sending the cancellation request on is still alive. The CancelToken, of course, can outlive the connection it was created from. Given how racy cancellation is in general, I don't think this is a big deal, but wanted to raise it nonetheless.

This comment has been minimized.

@sfackler

sfackler Dec 27, 2019
Owner

It cannot guarantee that. cancel_query is defined on Client, not Connection.

This comment has been minimized.

@benesch

benesch Dec 28, 2019
Author Contributor

Oh, good point, I forgot that the client lifetime wasn't tied to the connection lifetime. 👍

@benesch benesch force-pushed the benesch:synchronous-cancel branch from 2f53ac7 to 833782a Dec 28, 2019
@benesch
Copy link
Contributor Author

@benesch benesch commented Dec 28, 2019

Ok, updated to deprecate the tokio_postgres::Client::cancel_query[_raw] APIs and publicize the new CancelToken-based API in both tokio_postgres and postgres. Thoughts?

@@ -125,6 +126,8 @@ mod bind;
#[cfg(feature = "runtime")]
mod cancel_query;
mod cancel_query_raw;
#[doc(hidden)]
pub mod cancel_token;

This comment has been minimized.

@sfackler

sfackler Dec 29, 2019
Owner

This can be private.

This comment has been minimized.

@benesch

benesch Dec 29, 2019
Author Contributor

Oops, thanks.

@@ -304,6 +304,7 @@ async fn cancel_query_raw() {
let client = connect("user=postgres").await;

let socket = TcpStream::connect("127.0.0.1:5433").await.unwrap();
#[allow(deprecated)]
let cancel = client.cancel_query_raw(socket, NoTls);

This comment has been minimized.

@sfackler

sfackler Dec 29, 2019
Owner

Let's just switch these tests over to use the new APIs.

This comment has been minimized.

@benesch

benesch Dec 29, 2019
Author Contributor

You bet. Done.

@benesch benesch force-pushed the benesch:synchronous-cancel branch from 833782a to 33dbbcb Dec 29, 2019
@sfackler sfackler merged commit 7bd21b4 into sfackler:master Dec 31, 2019
1 check passed
1 check passed
ci/circleci Your tests passed on CircleCI!
Details
@sfackler
Copy link
Owner

@sfackler sfackler commented Dec 31, 2019

Thanks!

@benesch benesch deleted the benesch:synchronous-cancel branch Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.