Skip to content

fix: mitigate Linux webview renderer FD exhaustion during resource loading - #326272

Merged
Robo (deepak1556) merged 1 commit into
mainfrom
robo/webview_fd_mitigation
Jul 17, 2026
Merged

Robo (deepak1556) merged 1 commit into
mainfrom
robo/webview_fd_mitigation

Conversation

@deepak1556

@deepak1556 Robo (deepak1556) commented Jul 17, 2026 •

Copy link
Copy Markdown
Collaborator

Followup improvement for #326092

The issue surfaced a renderer forced exit after hitting EMFILE on Linux when a webview issued very large number of concurrent local resource fetches.

  • Codex extension can trigger roughly 625 concurrent webview resource requests.
  • Webview resource loading currently forwards each request to the host and begins transferring the returned body immediately.
  • Disk reads are chunked at 256 KiB, and Mojo uses shared-memory FDs for payloads above 64 KiB, so each in-flight resource body can consume file descriptors in the renderer while it is being streamed.
  • The sandboxed renderer runs with RLIMIT_NOFILE=1024 on Linux.
  • This is not specific to codex extension, any extension with enough concurrent resource bodies can accumulate to exhaust the renderer FD budget.

This makes the problem specifically about the number of simultaneously active host-backed response bodies. A naive limiter around WebviewElement.loadResource() would not address the root cause because loadResource returns as soon as the stream is transferred, while the FD pressure persists for the lifetime of the stream in the renderer.

Introduce a service-worker-side global concurrency limit for host-backed webview resource response bodies.

  • Add a global limit of 32 active host-backed resource bodies in the webview service worker.
  • Acquire a permit before creating/posting the load-resource request so time spent waiting for a slot does not consume the existing 30 second RequestStore timeout.
  • Hold the permit for the full lifetime of the returned ReadableStream, and release it only when the stream reaches EOF, errors, or is cancelled.
  • Release exactly once on all non-stream results and on every early/error path, including timeout handling.
  • Preserve existing range request behavior, ETag/304 handling, CacheStorage behavior, Safari fallback streaming, and cancellation semantics.
  • For cacheable responses, keep the permit until both source transfer and the associated cache write complete, without delaying delivery of the response back to the webview.
  • Bump the service worker version and WebviewElement expected version together so clients pick up the updated worker.

Tests

  • Add an API integration regression test that creates a webview, materializes many local resources, fetches them concurrently from inside the webview, and verifies the webview stays alive and all loads complete.

@deepak1556 Robo (deepak1556) added this to the 1.130.0 milestone Jul 17, 2026
@deepak1556 Robo (deepak1556) self-assigned this Jul 17, 2026
Copilot AI review requested due to automatic review settings July 17, 2026 02:41
@deepak1556 Robo (deepak1556) added the ~release-cherry-pick Trigger: cherry-pick this PR to the latest release branch label Jul 17, 2026
@vs-code-engineering

Copy link
Copy Markdown
Contributor

This PR will be automatically cherry-picked to release/1.129 when merged.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Mitigates Linux renderer FD exhaustion by limiting concurrent host-backed webview resource streams.

Changes:

  • Adds a 32-stream global semaphore with lifecycle-aware release handling.
  • Synchronizes the service worker version bump.
  • Adds a concurrent resource-loading integration test.
Show a summary per file
File Description
webviewElement.ts Updates the expected service worker version.
service-worker.js Implements response-body concurrency limiting and stream tracking.
webview.test.ts Adds concurrent local-resource coverage.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 3
  • Review effort level: Medium

…ading

Codex extension surfaced a renderer forced exit after hitting EMFILE on Linux
when a webview issued very large number of concurrent local resource fetches.

Diagnosis
- Codex extension can trigger roughly 625 concurrent webview resource requests.
- Webview resource loading currently forwards each request to the host and
  begins transferring the returned body immediately.
- Disk reads are chunked at 256 KiB, and Mojo uses shared-memory FDs for
  payloads above 64 KiB, so each in-flight resource body can consume file
  descriptors in the renderer while it is being streamed.
- The sandboxed renderer runs with RLIMIT_NOFILE=1024 on Linux.
- This is not specific to codex extensionn, any extension with enough concurrent
  resource bodies can accumulate to exhaust the renderer FD budget.

This makes the problem specifically about the number of simultaneously active
host-backed response bodies. A naive limiter around WebviewElement.loadResource()
would not address the root cause because loadResource() returns as soon as the
stream is transferred, while the FD pressure persists for the lifetime of the
stream in the renderer.

Introduce a service-worker-side global concurrency limit for host-backed webview
resource response bodies.

- Add a global limit of 32 active host-backed resource bodies in the webview
  service worker.
- Acquire a permit before creating/posting the load-resource request so time
  spent waiting for a slot does not consume the existing 30 second
  RequestStore timeout.
- Hold the permit for the full lifetime of the returned ReadableStream, and
  release it only when the stream reaches EOF, errors, or is cancelled.
- Release exactly once on all non-stream results and on every early/error path,
  including timeout handling.
- Preserve existing range request behavior, ETag/304 handling, CacheStorage
  behavior, Safari fallback streaming, and cancellation semantics.
- For cacheable responses, keep the permit until both source transfer and the
  associated cache write complete, without delaying delivery of the response
  back to the webview.
- Bump the service worker version and WebviewElement expected version together
  so clients pick up the updated worker.

Tests
- Add an API integration regression test that creates a webview, materializes
  many local resources, fetches them concurrently from inside the webview, and
  verifies the webview stays alive and all loads complete.

Co-authored-by: Copilot <[email protected]>
@deepak1556
Robo (deepak1556) force-pushed the robo/webview_fd_mitigation branch from a347398 to 62728f2 Compare July 17, 2026 18:48
@deepak1556
Robo (deepak1556) marked this pull request as ready for review July 17, 2026 19:05
@deepak1556
Robo (deepak1556) enabled auto-merge (squash) July 17, 2026 19:06
@deepak1556
Robo (deepak1556) merged commit 17d3b86 into main Jul 17, 2026
29 checks passed
@deepak1556
Robo (deepak1556) deleted the robo/webview_fd_mitigation branch July 17, 2026 20:09
Joe Politz (jpolitz) added a commit to jpolitz/pyret-lang that referenced this pull request Jul 29, 2026
Joe says:

Based on the typespec issue listed below, I'm pretty sure we hit some kind of
racy flake in VScode itself (separate commits fix our own race issues).

This commit forces our testing environment to use the same commit of vscode
that typespec went back to in order to fix their issue.

Claude says:

@vscode/test-web downloads the LATEST stable VS Code build at test time,
so every CI run floats on whatever Microsoft shipped last. VS Code
1.130.0 (commit 1b6a188127ee) was released 2026-07-22; on that build the
vscode env intermittently dies at boot: the .arr tab opens, the web
extension host starts, but resolveCustomTextEditor is never invoked --
no webview iframe, no error, no notification -- until the harness's
120s bound trips. Only the dev-extension jobs (vscode, both flavors)
hit it; the ovsx jobs, whose extension installs as a packaged VSIX and
so is registered before the workbench opens the file, never do. The
suite was green for weeks on 1.129.1 (8a7abeba6e03) and this exact
harness code has both green and red runs on 1.130.0, so the trigger is
the build rollover, not a commit of ours.

Independent confirmation: microsoft/typespec's vscode e2e suites (web
and desktop) started hanging the same day, were disabled to unblock CI,
and were re-enabled by pinning to this same 8a7abeba build:

  microsoft/typespec#11369
  microsoft/typespec#11383

The 1.130 release notes mention nothing about custom editors or the web
extension host, but the same race family exists upstream -- a file
opened at launch can resolve before a contributed custom editor is
registered, and a custom-editor open with no registered provider spins
forever with no error:

  microsoft/vscode#325506
  microsoft/vscode#96407
  https://code.visualstudio.com/updates/v1_130

1.130.0 changes plausibly retiming startup: the MessagePort IPC layer
now drops unparseable frames instead of erroring, and webview resource
loading gained a global stream semaphore:

  microsoft/vscode#326172
  microsoft/vscode#326272

The pin also makes this env deterministic, which "latest stable" never
was. Revisit when a post-1.130.0 stable proves green; as of today no
upstream issue tracks this regression, so ours may be the first report.

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01UWehNoCfHncXSWk6D3DFeQ
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Aug 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants