dotnet / dotnet/wpf

OutOfMemoryException from DUCE.Channel.SyncFlush()

Open
#8,397 10 comments 1 reaction 0 assignees View on GitHub
Investigate
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

### Description

One of our customers, is getting a weird `OutOfMemoryException` deep inside the framework code, even tho not much is happening in our app.

I've found these two other issues that seem similar: #7378 #8031

### Reproduction Steps

Sadly we can't reproduce the problem on any of our own machines.

But our customer is able to reliable reproduce the problem. We gathered some process-dumps during some crashes, and that's how we figured out everything we know so far.

We could maybe share those process-dumps with you.

### Expected behavior

Not getting an OutOfMemoryException, the application should keep working as usual.

### Actual behavior

The exception:

```
System.OutOfMemoryException: Insufficient memory to continue the execution of the program.
at System.Windows.Media.Composition.DUCE.Channel.SyncFlush()
at System.Windows.Interop.HwndTarget.UpdateWindowSettings(Boolean enableRenderTarget, Nullable`1 channelSet)
at System.Windows.Interop.HwndTarget.UpdateWindowPos(IntPtr lParam)
at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) in MS.Win32\HwndWrapper.cs:line 192
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) in MS.Win32\HwndSubclass.cs:line 223
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) in System.Windows.Threading\ExceptionWrapper.cs:line 73
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) in System.Windows.Threading\ExceptionWrapper.cs:line 24
```

It looks like this problem arises when a tooltip pops up in the app. I receive the System.OutOfMemoryException within the Dispatcher.UnhandledException event, with the following stacktrace.

However, it also could be unrelated.

```
OurApp.dll!OurApp.WPF.UI.App.Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e) Line 215 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.CatchException(System.Exception e) Line 1705 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.CatchExceptionStatic(object source, System.Exception e) Line 1692 C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.CatchException(object source, System.Exception e, System.Delegate catchHandler) Line 116 C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 28 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 981 C#
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Line 180 C#
[Native to Managed Transition]
[Managed to Native Transition]
PresentationCore.dll!System.Windows.Interop.HwndSource.Resize(System.Windows.Size newSize) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.OnLayoutUpdated(object obj, System.EventArgs args) Unknown
PresentationCore.dll!System.Windows.ContextLayoutManager.fireLayoutUpdateEvent() Unknown
PresentationCore.dll!System.Windows.ContextLayoutManager.UpdateLayout() Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.SetLayoutSize() Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisualInternal.set(System.Windows.Media.Visual value) Unknown
PresentationCore.dll!System.Windows.Interop.HwndSource.RootVisual.set(System.Windows.Media.Visual value) Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.SetRootVisualToPopupRoot() Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.CreateWindow(bool asyncCall) Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.OnIsOpenChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) Unknown
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Line 1354 C#
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) Line 1185 C#
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) Line 1133 C#
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) Line 811 C#
WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) Line 604 C#
PresentationFramework.dll!System.Windows.Data.BindingOperations.SetBinding(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp, System.Windows.Data.BindingBase binding) Unknown
PresentationFramework.dll!System.Windows.Controls.Primitives.Popup.CreateRootPopupInternal(System.Windows.Controls.Primitives.Popup popup, System.Windows.UIElement child, bool bindTreatMousePlacementAsBottomProperty) Unknown
PresentationFramework.dll!System.Windows.Controls.ToolTip.HookupParentPopup() Unknown
PresentationFramework.dll!System.Windows.Controls.ToolTip.OnIsOpenChanged(System.Windows.DependencyObject d, System.Windows.DependencyPropertyChangedEventArgs e) Unknown
WindowsBase.dll!System.Windows.DependencyObject.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Line 1354 C#
PresentationFramework.dll!System.Windows.FrameworkElement.OnPropertyChanged(System.Windows.DependencyPropertyChangedEventArgs e) Unknown
WindowsBase.dll!System.Windows.DependencyObject.NotifyPropertyChange(System.Windows.DependencyPropertyChangedEventArgs args) Line 1185 C#
WindowsBase.dll!System.Windows.DependencyObject.UpdateEffectiveValue(System.Windows.EntryIndex entryIndex, System.Windows.DependencyProperty dp, System.Windows.PropertyMetadata metadata, System.Windows.EffectiveValueEntry oldEntry, ref System.Windows.EffectiveValueEntry newEntry, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType) Line 1133 C#
WindowsBase.dll!System.Windows.DependencyObject.SetValueCommon(System.Windows.DependencyProperty dp, object value, System.Windows.PropertyMetadata metadata, bool coerceWithDeferredReference, bool coerceWithCurrentValue, System.Windows.OperationType operationType, bool isInternal) Line 811 C#
WindowsBase.dll!System.Windows.DependencyObject.SetValue(System.Windows.DependencyProperty dp, object value) Line 604 C#
PresentationFramework.dll!System.Windows.Controls.PopupControlService.ShowToolTip(System.Windows.DependencyObject o, bool fromKeyboard) Unknown
PresentationFramework.dll!System.Windows.Controls.PopupControlService.PromotePendingToolTipToCurrent(System.Windows.Controls.ToolTipService.TriggerAction triggerAction) Unknown
>>>> PresentationFramework.dll!System.Windows.Controls.PopupControlService.BeginShowToolTip.AnonymousMethod__0(object s, System.EventArgs e) Unknown
WindowsBase.dll!System.Windows.Threading.DispatcherTimer.FireTick() Line 254 C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 73 C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 24 C#
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() Line 424 C#
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(object obj) Line 100 C#
System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Unknown
WindowsBase.dll!MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 85 C#
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() Line 351 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() Line 1243 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 1359 C#
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) Line 192 C#
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) Line 223 C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) Line 73 C#
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.TryCatchWhen(object source, System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) Line 24 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) Line 981 C#
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) Line 180 C#
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) Line 1273 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame frame) Line 459 C#
WindowsBase.dll!System.Windows.Threading.Dispatcher.Run() Line 430 C#
PresentationFramework.dll!System.Windows.Application.RunDispatcher(object ignore) Unknown
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) Unknown
PresentationFramework.dll!System.Windows.Application.Run() Unknown
OurApp.dll!OurApp.WPF.UI.App.Main() C#

```

### Regression?

We don't know if this is a recent problem or if it's always been there for the customer. Neither do we know if just a single machine or windows-user is affected by it.

But we can pretty confidently say, that the issue doesn't seem very common, as our app doesn't show this issue on thousands of other machines.

### Known Workarounds

_No response_

### Impact

Our app crashes, and with it all unsaved changes are lost.

### Configuration

* .NET 6.0.19
* Microsoft Windows NT 10.0.22621.0 which I guess is Windows 11 Version 22H2
* x64

### Other information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.