-
Notifications
You must be signed in to change notification settings - Fork 177
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
Conversation
Co-authored-by: Maciej Hirsz <[email protected]>
* 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) ...
There was a problem hiding this 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.
ws-client/src/client.rs
Outdated
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), | ||
}; |
There was a problem hiding this comment.
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.
ws-client/src/helpers.rs
Outdated
rx: oneshot::Receiver<Result<T, Error>>, | ||
) -> Result<Result<T, Error>, oneshot::Canceled> { | ||
let timeout = crate::tokio::sleep(timeout); | ||
futures::pin_mut!(rx, timeout); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto about select!
macro
ws-client/Cargo.toml
Outdated
@@ -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"] } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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.