-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(providers): remove locks on requests #7156
Conversation
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.
nit
InnerTransport::Http(http) => http.call(req), | ||
InnerTransport::Ws(ws) => ws.call(req), | ||
InnerTransport::Ipc(ipc) => ipc.call(req), | ||
match this.inner.read().await.as_ref().unwrap().clone() { |
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.
we're acquiring this twice now we could do the this combined in an if let else
by checking this.inner.read().await.cloned()
also the write check still has a race condition, so we also need to check for is_none
there again
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 don't think we even need to clone since Service is implemented for &Http
and &Pubsub
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.
ah right, it works as long as we can obtain &mut &T
match this.inner.read().await.as_ref().unwrap() {
InnerTransport::Http(http) => {
let mut http = http;
http.call(req)
},
}
is there a cleaner way to do this without that strange let?
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.
Don't think so
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.
refactored it, now we don't clone and check second time after aquiring write lock
we can't use if let some there anymore I believe because we don't clone
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.
can do InnerTransport::Http(mut http)
?
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.
can do InnerTransport::Http(mut http)?
mut http
removes the reference
error[E0507]: cannot move out of a shared reference
--> crates/common/src/provider/runtime_transport.rs:228:19
|
228 | match inner.as_ref().expect("must've been initialized") {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
229 | InnerTransport::Http(mut http) => http.call(req),
| --------
| |
| data moved here
| move occurs because `http` has type `alloy_transport_http::Http<reqwest::Client>`, which does not implement the `Copy` trait
|
help: consider borrowing the pattern binding
|
229 | InnerTransport::Http(ref mut http) => http.call(req),
| +++
And ref mut
creates &mut T
when we want &mut &T
. This looks like a weird case that's not covered by patterns ig
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.
Amazing catch
Motivation
Closes #7131
We are basically blocking all async requests through provider rn by aquiring write lock before making a request.
Solution
Use read lock