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

Timeouts for all requests #406

Merged
merged 13 commits into from
Jul 8, 2021
Merged

Timeouts for all requests #406

merged 13 commits into from
Jul 8, 2021

Conversation

dvdplm
Copy link
Contributor

@dvdplm dvdplm commented Jul 6, 2021

Variant of #367

This PR takes a more opinionated stance than #367, where timeouts are optional. In this PR I suggest we make a all requests use a timeout and only let users choose the length.

niklasad1 and others added 8 commits June 2, 2021 20:34
Co-authored-by: Maciej Hirsz <1096222+maciejhirsz@users.noreply.github.com>
Variant of #367

This PR takes a more opinionated stance than #367, where timeouts are optional. In this PR I suggest we make a all requests use a timeout and only let users choose the length.
@dvdplm dvdplm requested a review from maciejhirsz July 6, 2021 16:58
dvdplm added 2 commits July 6, 2021 18:59
* master: (21 commits)
  New proc macro (#387)
  Streaming RpcParams parsing (#401)
  Set allowed Host header values (#399)
  Synchronization-less async connections in ws-server (#388)
  [ws server]: terminate already established connection(s) when the server is stopped (#396)
  feat: customizable JSON-RPC error codes via new enum variant on `CallErrror` (#394)
  [ci]: test each individual crate's manifest (#392)
  Add a way to stop servers (#386)
  [jsonrpsee types]: unify a couple of types + more tests (#389)
  Update roadmap link in readme (#390)
  Cross-origin protection (#375)
  Method aliases + RpcModule: Clone (#383)
  Use criterion's async bencher (#385)
  Async/subscription benches (#372)
  send text (#374)
  Fix link to ws server in README.md (#373)
  Concat -> simple push (#370)
  Add missing `rt` feature (#369)
  Release prep for v0.2 (#368)
  chore(scripts): publish script (#354)
  ...
Copy link
Contributor

@maciejhirsz maciejhirsz left a comment

Choose a reason for hiding this comment

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

Looks good, minor grumble.

Comment on lines 323 to 327
futures::pin_mut!(fut, timeout);
let res = match futures::future::select(fut, timeout).await {
futures::future::Either::Left((res, _)) => res,
futures::future::Either::Right((_, _)) => return Err(Error::RequestTimeout),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I reckon using futures::select! would improve readability here.

rx: oneshot::Receiver<Result<T, Error>>,
) -> Result<Result<T, Error>, oneshot::Canceled> {
let timeout = crate::tokio::sleep(timeout);
futures::pin_mut!(rx, timeout);
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto about select! macro

@@ -22,7 +22,7 @@ tokioV02-util = { package="tokio-util", version = "0.3", features = ["compat"],

async-trait = "0.1"
fnv = "1"
futures = { version = "0.3.14", default-features = false, features = ["std"] }
futures = { version = "0.3.14", default-features = false, features = ["std", "async-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.

@maciejhirsz I wonder if this was the reason for not using select!, to keep the required features down?

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting. The select! in futures also seems to have some weird requirements. Tokio has a select! macro that works identical, but doesn't require any .fuse() or pin_mut!() calls.

@dvdplm dvdplm merged commit 360a7f3 into master Jul 8, 2021
@dvdplm dvdplm deleted the dp-all-requests-timeout branch July 8, 2021 08:42
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