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

fix(providers): remove locks on requests #7156

Merged
merged 5 commits into from
Feb 17, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions crates/common/src/provider/runtime_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,19 +211,31 @@ impl RuntimeTransport {
pub fn request(&self, req: RequestPacket) -> TransportFut<'static> {
let this = self.clone();
Box::pin(async move {
if this.inner.read().await.is_none() {
let mut inner = this.inner.write().await;
*inner = Some(this.connect().await.map_err(TransportErrorKind::custom)?)
let mut inner = this.inner.read().await;
if inner.is_none() {
drop(inner);
let mut inner_mut = this.inner.write().await;
if inner_mut.is_none() {
*inner_mut = Some(this.connect().await.map_err(TransportErrorKind::custom)?);
}
drop(inner_mut);
klkvr marked this conversation as resolved.
Show resolved Hide resolved
inner = this.inner.read().await;
}

let mut inner = this.inner.write().await;
// SAFETY: We just checked that the inner transport exists.
let inner_mut = inner.as_mut().expect("We should have an inner transport.");

match inner_mut {
InnerTransport::Http(http) => http.call(req),
InnerTransport::Ws(ws) => ws.call(req),
InnerTransport::Ipc(ipc) => ipc.call(req),
match inner.as_ref().unwrap() {
klkvr marked this conversation as resolved.
Show resolved Hide resolved
InnerTransport::Http(http) => {
let mut http = http;
http.call(req)
}
InnerTransport::Ws(ws) => {
let mut ws = ws;
ws.call(req)
}
InnerTransport::Ipc(ipc) => {
let mut ipc = ipc;
ipc.call(req)
}
}
.await
})
Expand Down
Loading