Skip to content

test: release each browser test file's WebGL contexts when it ends - #11196

Closed
chrisgervang wants to merge 2 commits into
masterfrom
chr/release-webgl-contexts
Closed

chrisgervang wants to merge 2 commits into
masterfrom
chr/release-webgl-contexts

Conversation

@chrisgervang

@chrisgervang chrisgervang commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

For #11036

Background

The headless and browser projects run every file in one page. Deck and map instances keep their WebGL contexts after they are finalized, so contexts add up. Past Chromium's limit, it drops the oldest one, the shared test device, and every later GPU test fails with "WebGL context is lost". It depends on file order, so it shows up as flaky test-coverage and test-webgpu runs (for example on #11181 at 510b2f9, after maplibre/globe-icons-text.spec.ts).

Change List

  • test/setup/release-webgl-contexts.ts: loses each file's WebGL contexts in afterAll, keeping the shared test device
  • headless and browser projects load it

Split out of #11183, which needs it for its added browser specs. Verified with the full headless project: 286 files pass, no lost contexts.


Generated by Claude Code


Note

Low Risk
Test infrastructure change affecting only browser test suites with no runtime or production impact.

Overview
Adds a test setup helper (release-webgl-contexts.ts) that wraps HTMLCanvasElement.prototype.getContext to record WebGL contexts instantiated during a test file's run. At the end of each test file in afterAll, recorded contexts are explicitly destroyed using WEBGL_lose_context while preserving the shared test device.

Registers the new setup file in vitest.config.ts for both the headless and browser test projects. This prevents non-isolated Chromium sessions from exhausting WebGL context limits and causing downstream test flakiness.

Reviewed by Cursor Bugbot for commit cf9a622. Bugbot is set up for automated code reviews on this repo. Configure here.

The headless and browser projects run every file in one page. Deck and map
instances keep their WebGL contexts after they are finalized, so contexts that
files leave behind add up. When the page goes over Chromium's limit, Chromium
drops the oldest context, the shared test device, and every later GPU test
fails with "WebGL context is lost". Whether that happens depends on file order,
so it shows up as flaky coverage and webgpu runs.

A new setup file records the WebGL contexts each file creates and loses them in
afterAll, keeping the shared synchronous test device. luma.gl's async test
devices recreate themselves when their context is lost.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn
@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge based on this follow-up review.

Summary

Adds cleanup that releases WebGL contexts after each browser test file while keeping the shared test device.

  • Browser test files release their WebGL contexts when they finish.

No new issues found in the follow-up changes.

Reviews (2) · Last reviewed commit: "docs(test): document the context-release..." · Reviewed by Greptile

Comment thread test/setup/release-webgl-contexts.ts Resolved
@coveralls

coveralls commented Nov 18, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 82.521%. remained the same — chr/release-webgl-contexts into master

Copy link
Copy Markdown
Collaborator Author

Closing in favor of fixing the leak at its source. This setup file works, but it patches getContext for every browser test and hides leaks rather than fixing them.

The root cause is in deck.gl: Deck creates its device with _reuseDevices: true (modules/core/src/lib/deck.ts), so WebGLDevice.destroy() is a no-op, and even without that flag luma.gl leaves the context to garbage collection. Every finalized Deck keeps its WebGL context until GC, which is how the tests pass Chromium's limit. The plan is to release the context in Deck.finalize() when Deck created the canvas and device itself, and to fix any tests that leak for other reasons (for example by passing the shared test device). A PR for that will follow.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants