fix: Prevent OOM exception cascade in dispatcher handler#39
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
_handlingDispatcherExceptionflag, managed withInterlocked, prevents the handler from re-entering itself if it's already processing an exception. Subsequent rapid exceptions are swallowed to break the cascade.IsMemoryExhaustionhelper method detectsOutOfMemoryException(and its inner exceptions). If an OOM is detected, the handler avoids creating the WPF-basedCrashMessageBox.e.Handled = trueis 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