Skip to content

fix: Prevent OOM exception cascade in dispatcher handler#39

Merged
Jed556 merged 2 commits into
mainfrom
seer/fix/oom-exception-cascade
Jun 26, 2026
Merged

fix: Prevent OOM exception cascade in dispatcher handler#39
Jed556 merged 2 commits into
mainfrom
seer/fix/oom-exception-cascade

Conversation

@sentry

@sentry sentry Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The root cause analysis for AUTOMIDIPLAYER-14 identified that a System.OutOfMemoryException originating from WPF's rendering pipeline (Channel.SyncFlush) was being amplified into a storm of 31 identical errors. This occurred because the OnDispatcherUnhandledException handler in Bootstrapper.cs responded to the OOM by attempting to open a new CrashMessageBox window. Under memory pressure, creating this new window would itself trigger another OOM, leading to a re-entry into the handler and a continuous cascade of exceptions.

This fix addresses this by:

  1. Adding a re-entrancy guard: A static _handlingDispatcherException flag, managed with Interlocked, prevents the handler from re-entering itself if it's already processing an exception. Subsequent rapid exceptions are swallowed to break the cascade.
  2. Special-casing memory exhaustion: The IsMemoryExhaustion helper method detects OutOfMemoryException (and its inner exceptions). If an OOM is detected, the handler avoids creating the WPF-based CrashMessageBox.
  3. Implementing a lightweight failure path for OOM: For OOMs, the exception is captured and flushed to Sentry, and then the application is immediately shut down. This prevents further attempts to render UI elements that would likely fail and re-trigger the OOM.
  4. Explicitly handling exceptions: e.Handled = true is now explicitly set in all relevant paths to ensure the dispatcher doesn't re-process the exception.

This change ensures that a single memory exhaustion event results in a single, clean Sentry report and a graceful shutdown, rather than an overwhelming flood of errors.

Fixes AUTOMIDIPLAYER-14

@Jed556 Jed556 merged commit eb3f6f5 into main Jun 26, 2026
7 checks passed
@Jed556 Jed556 deleted the seer/fix/oom-exception-cascade branch June 26, 2026 02:29
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.

1 participant