Skip to content

deps: upgrade to tokio v1.0 ecosystem #717

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

Merged
merged 1 commit into from
Dec 25, 2020
Merged

Conversation

benesch
Copy link
Contributor

@benesch benesch commented Dec 24, 2020

@sfackler this is still waiting on releases of both tokio-openssl and tokio-native-tls that include the Tokio v1.0 bump, but I got tests for tokio-postgres and postgres passing, so figured I'd put this up.

@benesch
Copy link
Contributor Author

benesch commented Dec 24, 2020

Supersedes #688 and #716.

@sfackler
Copy link
Owner

tokio-openssl is updated.

@@ -153,7 +153,7 @@ impl Stream for BinaryCopyOutStream {
Some(header) => header.has_oids,
None => {
check_remaining(&chunk, HEADER_LEN)?;
if &chunk.bytes()[..MAGIC.len()] != MAGIC {
if &chunk.chunk()[..MAGIC.len()] != MAGIC {
Copy link
Owner

Choose a reason for hiding this comment

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

You should be able to just do if !chunk.starts_with(&MAGIC) here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chunk is a Cursor<Bytes> which unfortunately does not implement AsRef<[u8]>. Switched to !chunk.chunk().starts_with(&MAGIC).

The trait method Buf::chunk is not documented to return the whole slice, but the implementation of Buf for Cursor<Bytes> does make that guarantee. If relying on that is scary, we could instead do chunk.read_bytes(MAGIC.len()) != MAGIC, which is safe for any implementation of Buf.

Copy link
Owner

Choose a reason for hiding this comment

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

Oh - we should just remove the Cursor layer entirely since Bytes implements Buf directly now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried that, but we need access to the cursor position: https://github.com/sfackler/rust-postgres/blob/master/tokio-postgres/src/binary_copy.rs#L201

Could always do some pointer arithmetic to compute the position, but didn’t seem like an obvious win.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah right - should be fine as-is then.

@@ -46,7 +46,7 @@ impl BufRead for CopyOutReader<'_> {
};
}

Ok(self.cur.bytes())
Ok(self.cur.chunk())
Copy link
Owner

Choose a reason for hiding this comment

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

I think this can just be Ok(&self.cur).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@benesch benesch force-pushed the tokio-10 branch 3 times, most recently from 456fe29 to 56876af Compare December 24, 2020 18:43
@benesch
Copy link
Contributor Author

benesch commented Dec 24, 2020

All the TLS related crates have new releases now, so this is ready to go pending whatever review feedback you might have, @sfackler. As always feel free to just take over the PR.


fn connect(self, stream: S) -> Self::Future {
let future = async move {
let stream = tokio_openssl::connect(self.ssl, &self.domain, stream).await?;
let ssl = self.ssl.into_ssl(&self.domain)?;
let mut stream = Box::pin(SslStream::new(ssl, stream)?);
Copy link
Owner

Choose a reason for hiding this comment

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

Since S is Unpin, SslStream<S> is as well so there's no need to use Box::pin here. You should be able to just do Pin::new(&mut stream).connect().await;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah, thanks, that's much nicer. I missed the Unpin bound on S.

let stream = tokio_openssl::connect(self.ssl, &self.domain, stream).await?;
let ssl = self.ssl.into_ssl(&self.domain)?;
let mut stream = Box::pin(SslStream::new(ssl, stream)?);
stream.as_mut().connect().await?;
Copy link
Owner

Choose a reason for hiding this comment

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

I think it's worth doing something just a little bit more complicated to get better diagnostics after a certificate validation failure: https://github.com/sfackler/hyper-openssl/blob/master/src/lib.rs#L237-L240

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SGTM! I just shamelessly copy/pasted that code into here.

@@ -134,13 +134,15 @@ where
S: AsyncRead + AsyncWrite + Unpin + Debug + 'static + Sync + Send,
Copy link
Owner

Choose a reason for hiding this comment

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

You can remove the Debug + 'static + Sync bounds from here now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, Debug and Sync are gone. Compiler still insists on 'static though.

@sfackler
Copy link
Owner

Thanks! Looks good other than those few nits.

I think I'm probably just going to immediately cut a release with these dependency upgrades to get that out the door, and then start looking into cleaning things up for a 1.0 release from there.

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.

2 participants