Skip to content

[Web] Destroy GPUDevice once on buffer creation error#19790

Merged
guan404ming merged 2 commits into
apache:mainfrom
guan404ming:fix/webgpu-trycreatebuffer-destroy-once
Jun 16, 2026
Merged

[Web] Destroy GPUDevice once on buffer creation error#19790
guan404ming merged 2 commits into
apache:mainfrom
guan404ming:fix/webgpu-trycreatebuffer-destroy-once

Conversation

@guan404ming

Copy link
Copy Markdown
Member

Why

In tryCreateBuffer, each of the three popped error scopes independently called device.destroy() and console.error, so a buffer that triggers more than one error type destroyed the device repeatedly and logged duplicate errors.

How

  • Collect all three popErrorScope() results via Promise.all and call device.destroy() at most once
  • Log every captured error instead of relying on per-scope handlers

Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
@guan404ming guan404ming changed the title Destroy GPUDevice once on buffer creation error [Web] Destroy GPUDevice once on buffer creation error Jun 16, 2026

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request refactors the WebGPU error scope handling in webgpu.ts to use Promise.all, ensuring that device.destroy() is called at most once when multiple error types fire. The reviewer identified two important issues: a potential unhandled promise rejection if popErrorScope() rejects, and a TypeScript type narrowing issue where errors.filter does not automatically cast the array to GPUError[]. A code suggestion was provided to add a .catch() block and an explicit type guard.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread web/src/webgpu.ts
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@guan404ming guan404ming merged commit 27406a9 into apache:main Jun 16, 2026
9 checks passed
MasterJH5574 pushed a commit to MasterJH5574/tvm that referenced this pull request Jun 16, 2026
## Why

In `tryCreateBuffer`, each of the three popped error scopes
independently called `device.destroy()` and `console.error`, so a buffer
that triggers more than one error type destroyed the device repeatedly
and logged duplicate errors.

## How

- Collect all three `popErrorScope()` results via `Promise.all` and call
`device.destroy()` at most once
- Log every captured error instead of relying on per-scope handlers

---------

Signed-off-by: Guan-Ming (Wesley) Chiu <105915352+guan404ming@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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.

2 participants