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

Migrate to latest Tokio and Hyper #5

Merged
merged 14 commits into from
May 16, 2021

Conversation

mraerino
Copy link
Contributor

Refactoring the Stream types to:

  • Use Tokio 1.0
  • Replace reqwest with hyper & hyper-rustls
    • hyper brings less baggage and has a nameable response future
  • Update tests

Notes:

  • Introduces pin-project (proc macro), but that is required by Hyper anyway
  • HTTPS/h2 support is behind a feature (enabled by default)

@mraerino mraerino mentioned this pull request Feb 13, 2021
Comment on lines +27 to +29
pub use hyper::client::HttpConnector;
#[cfg(feature = "rustls")]
pub type HttpsConnector = RustlsConnector<HttpConnector>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are re-exported so people can name them when they use the Client<C>

reconnect_opts: ReconnectOptions,
}

/// Client that connects to a server using the Server-Sent Events protocol
/// and consumes the event stream indefinitely.
pub struct Client {
pub struct Client<C> {
http: hyper::Client<C>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is very cheap to clone and all clones will share a single connection pool

}

fn backoff(&mut self) -> Duration {
fn backoff(mut self: Pin<&mut Self>) -> Duration {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

made the receiver Pin because these only get called from poll_next and this makes some things easier

Copy link
Contributor

@samstokes samstokes left a comment

Choose a reason for hiding this comment

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

Hi, @mraerino! I'm super excited you took the time to bring our code into the 21st century - this must have taken a fair amount of work.

Sorry for taking a really long time to respond to this PR. I wanted to take the time before responding to port our not-yet-public SDK over to the new APIs, and run our internal compatibility test suite against it. I'm pleased to report the SDK works fine with your branch, although it does appear to expose an existing bug.

At the high level I'm 100% on board with the goal and approach. I'd love to support the latest tokio/futures APIs, and be async/await-compatible.

This is complicated slightly by a bugfix (#6) I've been working on that conflicts with this change. I do want to land the bugfix first since it's a correctness issue, but I'm happy to help with resolving the merge conflict once it's in. I had a go at resolving the conflict myself but it's fairly involved, since both PRs make nontrivial changes to Decoded::poll.

Again, thank you for spending the time to do this and for contributing your work back - I'm excited to get this merged in.

src/client.rs Outdated
}
};
self.as_mut().project().state.set(new_state);
self.poll_next(cx)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is replacing a loop {} with a recursive call, correct? Is that the idiomatic way to write stream combinators in modern async Rust?

This is intuitively a little surprising to me, and according to a (very) brief Google search, tail call optimisation is possible but not guaranteed. We would obviously not want a possibility of stack overflow, given that these streams could be very long-lived (I believe we regularly see stream connections open for days).

Very willing to be convinced that I'm behind the times and this is a normal and reasonable thing to do :)

Similar question about Decoded::poll_next.

Copy link
Contributor

Choose a reason for hiding this comment

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

I did some more research and found this article which also seems to suggest that TCO is not guaranteed, so I took the liberty of changing this back to a loop: eebd97b

@samstokes
Copy link
Contributor

Hi @mraerino, wanted to let you know that I ported my fix from #6 to this branch and resolved the merge conflicts (Github allows me to push to your branch because you opened a PR for it), so I'm happy to merge this in now! Thanks again for taking the time to make these improvements and for contributing your work back so other folks can benefit.

@samstokes samstokes merged commit 812aa83 into launchdarkly:master May 16, 2021
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