Repository navigation
fix: fetch fd leak - #31375
fix: fetch fd leak#31375
Conversation
WalkthroughThe PR replaces per-thread HTTP client caching with a single shared client. In cli/http_util.rs, HttpClientProvider’s Sequence Diagram(s)sequenceDiagram
actor Caller
participant OldHttpUtil as cli::HttpClientProvider (old)
participant MutexMap as Mutex<HashMap<ThreadId, Client>>
participant NewHttpUtil as cli::HttpClientProvider (new)
participant OnceCell as OnceCell<Client>
participant Client as deno_fetch::Client
Note over Caller,OldHttpUtil: Old flow (per-thread)
Caller->>OldHttpUtil: get_or_create(thread_id, options)
OldHttpUtil->>MutexMap: lock & lookup(thread_id)
alt entry exists
MutexMap-->>OldHttpUtil: existing Client
else
MutexMap-->>OldHttpUtil: insert new Client from options
end
OldHttpUtil-->>Caller: HttpClient(wrapped per-thread Client)
Note over Caller,NewHttpUtil: New flow (shared)
Caller->>NewHttpUtil: get_or_create(options)
NewHttpUtil->>OnceCell: get_or_try_init(() -> create Client from options)
alt init needed
OnceCell-->>NewHttpUtil: new Client
else
OnceCell-->>NewHttpUtil: existing Client
end
NewHttpUtil-->>Caller: HttpClient(wrapping shared Client)
sequenceDiagram
actor WebWorker
participant OldFetch as sync_fetch.rs (old)
participant NewFetch as sync_fetch.rs (new)
participant Options as Options
participant State as WorkerState
participant Client as deno_fetch::Client
Note over WebWorker,OldFetch: Old per-call creation
WebWorker->>OldFetch: sync_fetch(...)
OldFetch->>Options: read client options
Options-->>OldFetch: options
OldFetch->>Client: create client from options
Client-->>OldFetch: Client
OldFetch-->>WebWorker: proceed with fetch using Client
Note over WebWorker,NewFetch: New state-backed retrieval
WebWorker->>NewFetch: sync_fetch(...)
NewFetch->>State: deno_fetch::get_or_create_client_from_state(state)
State-->>NewFetch: Client
NewFetch-->>WebWorker: proceed with fetch using Client
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🧰 Additional context used🧬 Code graph analysis (2)runtime/ops/web_worker/sync_fetch.rs (1)
cli/http_util.rs (1)
🔇 Additional comments (6)
Comment |
6a68806 to
68b904d
Compare
f8b348d to
3eed2cc
Compare
3eed2cc to
031f8c2
Compare
Solution for: #31080 Modern reqwest (0.12+) can safely share clients across tokio runtimes. Because it uses the current runtime's executor instead of spawning background threads. Using a single shared client prevents resource leaks when worker threads terminate. ## Context It seems that we started to use one client per thread because hyper and reqwest was not safe to share across tokio runtimes (#23699). But seems it's fixed at latest reqwest versions (seanmonstar/reqwest#1148 (comment)). This PR is using one client again, as we now already use the version of reqwest with this fix.
Solution for: denoland#31080 Modern reqwest (0.12+) can safely share clients across tokio runtimes. Because it uses the current runtime's executor instead of spawning background threads. Using a single shared client prevents resource leaks when worker threads terminate. ## Context It seems that we started to use one client per thread because hyper and reqwest was not safe to share across tokio runtimes (denoland#23699). But seems it's fixed at latest reqwest versions (seanmonstar/reqwest#1148 (comment)). This PR is using one client again, as we now already use the version of reqwest with this fix.
Solution for: #31080
Modern reqwest (0.12+) can safely share clients across tokio runtimes.
Because it uses the current runtime's executor instead of spawning background threads.
Using a single shared client prevents resource leaks when worker threads terminate.
Context
It seems that we started to use one client per thread because hyper and reqwest was not safe to share across tokio runtimes (#23699). But seems it's fixed at latest reqwest versions (seanmonstar/reqwest#1148 (comment)).
This PR is using one client again, as we now already use the version of reqwest with this fix.