From d527b635753566e7d01391d675bf010c4856eff9 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sun, 5 May 2024 10:07:21 -0400 Subject: fix(workers): `importScripts` concurrently and use a new `reqwest::Client` per importScripts (#23699) 1. We were polling each future in sequence, so this meant it was fetching scripts in sequence. 2. It's not safe to share `reqwest::Client` across tokio runtimes (https://github.com/seanmonstar/reqwest/issues/1148#issuecomment-910868788) --- ext/fetch/lib.rs | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'ext/fetch') diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index e384a918e..3e43370d3 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -187,27 +187,33 @@ pub fn get_or_create_client_from_state( Ok(client.clone()) } else { let options = state.borrow::(); - let client = create_http_client( - &options.user_agent, - CreateHttpClientOptions { - root_cert_store: options.root_cert_store()?, - ca_certs: vec![], - proxy: options.proxy.clone(), - unsafely_ignore_certificate_errors: options - .unsafely_ignore_certificate_errors - .clone(), - client_cert_chain_and_key: options.client_cert_chain_and_key.clone(), - pool_max_idle_per_host: None, - pool_idle_timeout: None, - http1: true, - http2: true, - }, - )?; + let client = create_client_from_options(options)?; state.put::(client.clone()); Ok(client) } } +pub fn create_client_from_options( + options: &Options, +) -> Result { + create_http_client( + &options.user_agent, + CreateHttpClientOptions { + root_cert_store: options.root_cert_store()?, + ca_certs: vec![], + proxy: options.proxy.clone(), + unsafely_ignore_certificate_errors: options + .unsafely_ignore_certificate_errors + .clone(), + client_cert_chain_and_key: options.client_cert_chain_and_key.clone(), + pool_max_idle_per_host: None, + pool_idle_timeout: None, + http1: true, + http2: true, + }, + ) +} + #[allow(clippy::type_complexity)] pub struct ResourceToBodyAdapter( Rc, -- cgit v1.2.3