Skip to content

Commit b6a1326

Browse files
committed
wip
1 parent a4fb509 commit b6a1326

File tree

1 file changed

+39
-25
lines changed
  • crates/rproxy/src/server/proxy/http

1 file changed

+39
-25
lines changed

crates/rproxy/src/server/proxy/http/proxy.rs

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ where
7777
shared: ProxyHttpSharedState<C, P>,
7878

7979
backend: ProxyHttpBackendEndpoint<C, P>,
80-
requests: HashMap<Uuid, ProxiedHttpRequest>,
80+
requests: Arc<HashMap<Uuid, ProxiedHttpRequest>>,
8181
postprocessor: actix::Addr<ProxyHttpPostprocessor<C, P>>,
8282
}
8383

@@ -130,7 +130,7 @@ where
130130
}
131131
.start();
132132

133-
Self { id, shared, backend, requests: HashMap::default(), postprocessor }
133+
Self { id, shared, backend, requests: Arc::new(HashMap::default()), postprocessor }
134134
}
135135

136136
pub(crate) async fn run(
@@ -641,35 +641,49 @@ where
641641
}
642642

643643
fn postprocess_client_request(&self, req: ProxiedHttpRequest) {
644-
let id = req.info.req_id;
644+
let req_id = req.info.req_id;
645645
let conn_id = req.info.conn_id;
646+
let worker_id = self.id;
646647

647-
if self.requests.insert_sync(id, req).is_err() {
648-
error!(
649-
proxy = P::name(),
650-
request_id = %id,
651-
connection_id = %conn_id,
652-
worker_id = %self.id,
653-
"Duplicate request id",
654-
);
655-
};
648+
let requests = self.requests.clone();
649+
650+
actix_web::rt::task::spawn_blocking(move || {
651+
if requests.insert_sync(req_id, req).is_err() {
652+
error!(
653+
proxy = P::name(),
654+
request_id = %req_id,
655+
connection_id = %conn_id,
656+
worker_id = %worker_id,
657+
"Duplicate request id",
658+
);
659+
};
660+
});
656661
}
657662

658663
fn postprocess_backend_response(&self, bknd_res: ProxiedHttpResponse) {
659-
let Some((_, clnt_req)) = self.requests.remove_sync(&bknd_res.info.req_id) else {
660-
error!(
661-
proxy = P::name(),
662-
request_id = %bknd_res.info.req_id,
663-
connection_id = %bknd_res.info.conn_id,
664-
worker_id = %self.id,
665-
"Proxied http response for unmatching request",
666-
);
667-
return;
668-
};
664+
let req_id = bknd_res.info.req_id;
665+
let conn_id = bknd_res.info.conn_id;
666+
let worker_id = self.id;
667+
668+
let requests = self.requests.clone();
669+
let postprocessor = self.postprocessor.clone();
670+
671+
actix_web::rt::task::spawn_blocking(move || {
672+
let Some((_, clnt_req)) = requests.remove_sync(&req_id) else {
673+
error!(
674+
proxy = P::name(),
675+
request_id = %req_id,
676+
connection_id = %conn_id,
677+
worker_id = %worker_id,
678+
"Proxied http response for unmatching request",
679+
);
680+
return;
681+
};
669682

670-
// hand over to postprocessor asynchronously so that we can return the
671-
// response to the client as early as possible
672-
self.postprocessor.do_send(ProxiedHttpCombo { req: clnt_req, res: bknd_res });
683+
// hand over to postprocessor asynchronously so that we can return the
684+
// response to the client as early as possible
685+
postprocessor.do_send(ProxiedHttpCombo { req: clnt_req, res: bknd_res });
686+
});
673687
}
674688

675689
fn finalise_proxying(

0 commit comments

Comments
 (0)