Skip to content

fix(desktop): add GPU crash detection and resource cleanup#10280

Merged
originalix merged 9 commits intoxfrom
fix/desktop-gpu-crash-protection
Feb 24, 2026
Merged

fix(desktop): add GPU crash detection and resource cleanup#10280
originalix merged 9 commits intoxfrom
fix/desktop-gpu-crash-protection

Conversation

@huhuanming
Copy link
Copy Markdown
Contributor

@huhuanming huhuanming commented Feb 17, 2026

Summary

Implements comprehensive GPU crash protection system for Windows desktop to prevent GPU process crashes when using DApp browser with heavy content (e.g., aave.com, uniswap).

Related: Sentry GPU crash reports on Windows AMD + heavy DApp usage

Changes

1. GPU Crash Detection & Monitoring (apps/desktop/app/app.ts)

  • ✅ Monitor GPU process crashes via child-process-gone event
  • ✅ Record crash statistics (count & timestamp) to persistent storage
  • ✅ Report crashes to Sentry with detailed context (platform, CPU model, crash count)
  • ✅ Notify renderer process of crash events via IPC
  • ✅ Monitor render process crashes (may be GPU-related)
  • ✅ Track GPU info updates

2. GPU Resource Limits (apps/desktop/app/app.ts)

  • ✅ Limit GPU compositing framerate to 60fps on Windows/Linux
  • ✅ Reduce GPU load to prevent memory exhaustion

3. Webview Resource Cleanup (DesktopBrowserContent.tsx)

  • ✅ Release GPU resources when browser tabs close
  • ✅ Close DevTools to free GPU memory
  • ✅ Stop all media playback (audio/video)
  • ✅ Clear history to free memory
  • ✅ Remove webview references for garbage collection

4. Crash Statistics Storage (store.ts, desktop.ts)

  • recordGPUCrash() - Track crash events
  • getGPUCrashStats() - Retrieve crash statistics
  • clearGPUCrashStats() - Clear statistics
  • ✅ Persistent storage keys: GPUCrashCount, LastGPUCrashTime

Test Plan

  • Code compiles without errors
  • Test on Windows with AMD GPU
  • Open 5-10 DApp browser tabs with heavy content
  • Verify GPU memory is released when tabs close
  • Check Sentry for crash reports with correct context
  • Verify crash statistics are persisted
  • Check logs for GPU Protection System initialization message

Impact

Before: GPU crashes would cause the entire app to freeze/crash, losing user work

After:

  • GPU crashes are detected and logged
  • Statistics tracked for monitoring
  • Resources properly cleaned up
  • Sentry receives detailed crash reports for analysis
  • Users can continue using the app (Electron auto-recovers GPU process)

Technical Details

Files Changed: 4 files, +159 lines

  • apps/desktop/app/app.ts - Main GPU protection logic
  • apps/desktop/app/libs/store.ts - Crash statistics storage
  • packages/kit/src/views/Discovery/pages/Browser/DesktopBrowserContent.tsx - Resource cleanup
  • packages/shared/types/desktop.ts - Type definitions

Note: This implementation does NOT automatically disable hardware acceleration. It only monitors and reports crashes, allowing users to keep GPU acceleration enabled for better performance.

🤖 Generated with Claude Code


Open with Devin

Implement comprehensive GPU crash protection system for Windows desktop:

1. GPU Crash Detection:
   - Monitor GPU process crashes via child-process-gone event
   - Record crash statistics (count & timestamp) to local storage
   - Report crashes to Sentry with detailed context
   - Notify renderer process of crash events

2. GPU Resource Limits:
   - Limit GPU compositing framerate to 60fps on Windows/Linux
   - Reduce GPU load to prevent memory exhaustion

3. Webview Resource Cleanup:
   - Release GPU resources when browser tabs close
   - Close DevTools, stop media playback, clear history
   - Remove webview references for garbage collection

4. Crash Monitoring:
   - Track render process crashes (GPU-related)
   - Monitor GPU info updates
   - Log crash patterns for analysis

Related: Sentry GPU crash reports on Windows AMD + heavy DApp usage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@revan-zhang
Copy link
Copy Markdown
Contributor

revan-zhang commented Feb 17, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

devin-ai-integration[bot]

This comment was marked as resolved.

…n system

Implements comprehensive memory leak prevention to fix OOM crashes that occur after ~3 hours of DApp browser usage (5.6GB memory consumption).

**三个关键修复点:**

1. **WebView 彻底清理** (DesktopBrowserContent.tsx)
   - 清除所有 JavaScript 定时器和间隔
   - 取消动画帧
   - 停止媒体播放
   - 清除缓存和 session 存储
   - 释放 webview 引用以允许垃圾回收

2. **内存监控系统** (app.ts)
   - 每 60 秒监控内存使用
   - 1GB 警告阈值:通知渲染进程
   - 2GB 临界阈值:触发激进清理和标签页重载
   - Sentry 集成用于监控

3. **自动标签页重载** (useMemoryPressureHandler.desktop.ts)
   - 监听主进程的内存压力事件
   - 1GB+:显示警告提示
   - 2GB+:自动重载不活跃标签页释放内存

**预期效果:**
- 内存泄漏率: 1.87GB/小时 → <10MB/小时
- 最大内存使用: 5.6GB → <500MB
- 消除 OOM 崩溃风险

Related: Sentry OOM crash report (Event ID: ce3d5a42f2784755b9408ab85bb60b48)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

huhuanming and others added 2 commits February 18, 2026 00:30
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
devin-ai-integration[bot]

This comment was marked as resolved.

…tance launch

Fixes crash when user launches OneKey Desktop while it's already running on Linux.

Root cause: Second instance handler was calling showMainWindow() twice, triggering
renderer process re-initialization and causing webview custom element to be registered
twice, resulting in NotSupportedError crash.

Changes:
1. Use app.quit() instead of quitOrMinimizeApp() for immediate second instance exit
2. Remove duplicate showMainWindow() call (handleDeepLinkUrl already calls it)
3. Unify deep link handling for all platforms (Linux was excluded before)
4. Fix isColdStartup parameter (false for second instance, not true)

Sentry: 9ce8e3ae9db24a7a95cdae385acb4048
- Remove ineffective `max-gum-fps` flag (controls getUserMedia, not GPU compositing)
- Fix stale closure in useMemoryPressureHandler by using refs for tabs/currentTabId
- Add IPC listener cleanup on unmount to prevent listener leaks
- Remove shared session cache clearing that destroyed cache for all open tabs
devin-ai-integration[bot]

This comment was marked as resolved.

@huhuanming huhuanming enabled auto-merge (squash) February 24, 2026 03:42
…cleanup

- Add memory-pressure-warning, memory-pressure-critical, gpu-process-crashed
  to validChannels in preload.ts so renderer can receive these IPC messages
- Use desktopApi.on() return value as cleanup function instead of
  non-existent desktopApi.removeListener()
devin-ai-integration[bot]

This comment was marked as resolved.

… clearing

- Only fire IPC events on threshold transitions (below→above), not every
  60-second poll interval, preventing toast spam and repeated tab reloads
- Remove session.clearCache() from main process critical handler since it
  destroys cache for all webviews and causes reloaded tabs to re-fetch
  everything without cache, counterproductively increasing memory usage
- Remove per-webview session.clearCache() in renderer critical handler
  for the same shared-session reason
@originalix originalix disabled auto-merge February 24, 2026 06:11
@originalix originalix merged commit cea56e1 into x Feb 24, 2026
10 checks passed
@originalix originalix deleted the fix/desktop-gpu-crash-protection branch February 24, 2026 06:11
0xchloe996 pushed a commit to 0xchloe996/app-monorepo that referenced this pull request Feb 24, 2026
…10280)

* fix(desktop): add GPU crash detection and resource cleanup

Implement comprehensive GPU crash protection system for Windows desktop:

1. GPU Crash Detection:
   - Monitor GPU process crashes via child-process-gone event
   - Record crash statistics (count & timestamp) to local storage
   - Report crashes to Sentry with detailed context
   - Notify renderer process of crash events

2. GPU Resource Limits:
   - Limit GPU compositing framerate to 60fps on Windows/Linux
   - Reduce GPU load to prevent memory exhaustion

3. Webview Resource Cleanup:
   - Release GPU resources when browser tabs close
   - Close DevTools, stop media playback, clear history
   - Remove webview references for garbage collection

4. Crash Monitoring:
   - Track render process crashes (GPU-related)
   - Monitor GPU info updates
   - Log crash patterns for analysis

Related: Sentry GPU crash reports on Windows AMD + heavy DApp usage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(desktop): prevent OOM crash in DApp browser with memory protection system

Implements comprehensive memory leak prevention to fix OOM crashes that occur after ~3 hours of DApp browser usage (5.6GB memory consumption).

**三个关键修复点:**

1. **WebView 彻底清理** (DesktopBrowserContent.tsx)
   - 清除所有 JavaScript 定时器和间隔
   - 取消动画帧
   - 停止媒体播放
   - 清除缓存和 session 存储
   - 释放 webview 引用以允许垃圾回收

2. **内存监控系统** (app.ts)
   - 每 60 秒监控内存使用
   - 1GB 警告阈值:通知渲染进程
   - 2GB 临界阈值:触发激进清理和标签页重载
   - Sentry 集成用于监控

3. **自动标签页重载** (useMemoryPressureHandler.desktop.ts)
   - 监听主进程的内存压力事件
   - 1GB+:显示警告提示
   - 2GB+:自动重载不活跃标签页释放内存

**预期效果:**
- 内存泄漏率: 1.87GB/小时 → <10MB/小时
- 最大内存使用: 5.6GB → <500MB
- 消除 OOM 崩溃风险

Related: Sentry OOM crash report (Event ID: ce3d5a42f2784755b9408ab85bb60b48)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(lint): remove unused 'level' variables in memory pressure handler

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix lint

* fix(desktop): prevent webview double registration crash on second instance launch

Fixes crash when user launches OneKey Desktop while it's already running on Linux.

Root cause: Second instance handler was calling showMainWindow() twice, triggering
renderer process re-initialization and causing webview custom element to be registered
twice, resulting in NotSupportedError crash.

Changes:
1. Use app.quit() instead of quitOrMinimizeApp() for immediate second instance exit
2. Remove duplicate showMainWindow() call (handleDeepLinkUrl already calls it)
3. Unify deep link handling for all platforms (Linux was excluded before)
4. Fix isColdStartup parameter (false for second instance, not true)

Sentry: 9ce8e3ae9db24a7a95cdae385acb4048

* fix(desktop): address GPU crash protection review issues

- Remove ineffective `max-gum-fps` flag (controls getUserMedia, not GPU compositing)
- Fix stale closure in useMemoryPressureHandler by using refs for tabs/currentTabId
- Add IPC listener cleanup on unmount to prevent listener leaks
- Remove shared session cache clearing that destroyed cache for all open tabs

* fix(desktop): register memory pressure IPC channels and fix listener cleanup

- Add memory-pressure-warning, memory-pressure-critical, gpu-process-crashed
  to validChannels in preload.ts so renderer can receive these IPC messages
- Use desktopApi.on() return value as cleanup function instead of
  non-existent desktopApi.removeListener()

* fix(desktop): throttle memory pressure events and remove shared cache clearing

- Only fire IPC events on threshold transitions (below→above), not every
  60-second poll interval, preventing toast spam and repeated tab reloads
- Remove session.clearCache() from main process critical handler since it
  destroys cache for all webviews and causes reloaded tabs to re-fetch
  everything without cache, counterproductively increasing memory usage
- Remove per-webview session.clearCache() in renderer critical handler
  for the same shared-session reason

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
PatrickChoo pushed a commit to PatrickChoo/app-monorepo that referenced this pull request Mar 10, 2026
…10280)

* fix(desktop): add GPU crash detection and resource cleanup

Implement comprehensive GPU crash protection system for Windows desktop:

1. GPU Crash Detection:
   - Monitor GPU process crashes via child-process-gone event
   - Record crash statistics (count & timestamp) to local storage
   - Report crashes to Sentry with detailed context
   - Notify renderer process of crash events

2. GPU Resource Limits:
   - Limit GPU compositing framerate to 60fps on Windows/Linux
   - Reduce GPU load to prevent memory exhaustion

3. Webview Resource Cleanup:
   - Release GPU resources when browser tabs close
   - Close DevTools, stop media playback, clear history
   - Remove webview references for garbage collection

4. Crash Monitoring:
   - Track render process crashes (GPU-related)
   - Monitor GPU info updates
   - Log crash patterns for analysis

Related: Sentry GPU crash reports on Windows AMD + heavy DApp usage

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(desktop): prevent OOM crash in DApp browser with memory protection system

Implements comprehensive memory leak prevention to fix OOM crashes that occur after ~3 hours of DApp browser usage (5.6GB memory consumption).

**三个关键修复点:**

1. **WebView 彻底清理** (DesktopBrowserContent.tsx)
   - 清除所有 JavaScript 定时器和间隔
   - 取消动画帧
   - 停止媒体播放
   - 清除缓存和 session 存储
   - 释放 webview 引用以允许垃圾回收

2. **内存监控系统** (app.ts)
   - 每 60 秒监控内存使用
   - 1GB 警告阈值:通知渲染进程
   - 2GB 临界阈值:触发激进清理和标签页重载
   - Sentry 集成用于监控

3. **自动标签页重载** (useMemoryPressureHandler.desktop.ts)
   - 监听主进程的内存压力事件
   - 1GB+:显示警告提示
   - 2GB+:自动重载不活跃标签页释放内存

**预期效果:**
- 内存泄漏率: 1.87GB/小时 → <10MB/小时
- 最大内存使用: 5.6GB → <500MB
- 消除 OOM 崩溃风险

Related: Sentry OOM crash report (Event ID: ce3d5a42f2784755b9408ab85bb60b48)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix(lint): remove unused 'level' variables in memory pressure handler

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

* fix lint

* fix(desktop): prevent webview double registration crash on second instance launch

Fixes crash when user launches OneKey Desktop while it's already running on Linux.

Root cause: Second instance handler was calling showMainWindow() twice, triggering
renderer process re-initialization and causing webview custom element to be registered
twice, resulting in NotSupportedError crash.

Changes:
1. Use app.quit() instead of quitOrMinimizeApp() for immediate second instance exit
2. Remove duplicate showMainWindow() call (handleDeepLinkUrl already calls it)
3. Unify deep link handling for all platforms (Linux was excluded before)
4. Fix isColdStartup parameter (false for second instance, not true)

Sentry: 9ce8e3ae9db24a7a95cdae385acb4048

* fix(desktop): address GPU crash protection review issues

- Remove ineffective `max-gum-fps` flag (controls getUserMedia, not GPU compositing)
- Fix stale closure in useMemoryPressureHandler by using refs for tabs/currentTabId
- Add IPC listener cleanup on unmount to prevent listener leaks
- Remove shared session cache clearing that destroyed cache for all open tabs

* fix(desktop): register memory pressure IPC channels and fix listener cleanup

- Add memory-pressure-warning, memory-pressure-critical, gpu-process-crashed
  to validChannels in preload.ts so renderer can receive these IPC messages
- Use desktopApi.on() return value as cleanup function instead of
  non-existent desktopApi.removeListener()

* fix(desktop): throttle memory pressure events and remove shared cache clearing

- Only fire IPC events on threshold transitions (below→above), not every
  60-second poll interval, preventing toast spam and repeated tab reloads
- Remove session.clearCache() from main process critical handler since it
  destroys cache for all webviews and causes reloaded tabs to re-fetch
  everything without cache, counterproductively increasing memory usage
- Remove per-webview session.clearCache() in renderer critical handler
  for the same shared-session reason

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.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.

3 participants