fix: do not share http_client in js_eval runtime

This commit is contained in:
Ruben Fiszel
2023-10-25 09:51:20 +02:00
parent 203192b440
commit 4a4b3bea0c
3 changed files with 21 additions and 4 deletions
+1
View File
@@ -638,6 +638,7 @@ async fn handle_zombie_jobs<R: rsmq_async::RsmqConnection + Send + Sync + Clone>
base_internal_url: base_internal_url.to_string(),
token,
workspace: job.workspace_id.to_string(),
force_client: None,
};
let last_ping = job.last_ping.clone();
+8 -1
View File
@@ -173,7 +173,14 @@ pub async fn eval_timeout(
{
let op_state = js_runtime.op_state();
let mut op_state = op_state.borrow_mut();
op_state.put(OptAuthedClient(authed_client.clone()));
let mut client = authed_client.clone();
if let Some(client) = client.as_mut() {
client.force_client = Some(reqwest::ClientBuilder::new()
.user_agent("windmill/beta")
.danger_accept_invalid_certs(std::env::var("ACCEPT_INVALID_CERTS").is_ok())
.build().unwrap());
}
op_state.put(OptAuthedClient(client));
op_state.put(TransformContext {
flow_input: if has_flow_input { flow_input } else { None },
envs: transform_context
+12 -3
View File
@@ -300,6 +300,7 @@ impl AuthedClientBackgroundTask {
base_internal_url: self.base_internal_url.clone(),
workspace: self.workspace.clone(),
token: self.get_token().await,
force_client: None,
};
}
pub async fn get_token(&self) -> String {
@@ -311,11 +312,15 @@ pub struct AuthedClient {
pub base_internal_url: String,
pub workspace: String,
pub token: String,
pub force_client: Option<reqwest::Client>,
}
impl AuthedClient {
pub async fn get(&self, url: &str, query: Vec<(&str, String)>) -> anyhow::Result<Response> {
Ok(HTTP_CLIENT
Ok(self
.force_client
.as_ref()
.unwrap_or(&HTTP_CLIENT)
.get(url)
.query(&query)
.header(
@@ -450,8 +455,12 @@ async fn handle_receive_completed_job<
let metrics = build_language_metrics(&worker_execution_failed.clone(), &jc.job.language);
let token = jc.token.clone();
let workspace = jc.job.workspace_id.clone();
let client =
AuthedClient { base_internal_url: base_internal_url.to_string(), workspace, token };
let client = AuthedClient {
base_internal_url: base_internal_url.to_string(),
workspace,
token,
force_client: None,
};
let job = jc.job.clone();
let mem_peak = jc.mem_peak.clone();
if let Err(err) = process_completed_job(