WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: CoreWebView2Controller.Close() sometimes hangs when disposing a windows forms webview2 browser control

Open peh-87 opened this issue 1 year ago • 4 comments

What happened?

We are using an instance of a WebView2 browser control within our application. The Microsoft.Web.WebView2.WinForms.WebView2 control is embedded within a user control of our own.

When shutting down the application, it will sometimes hang within DestroyWindow, which is called within the EmbeddedBrowserWebView.dll triggered by CoreWebView2Controller.Close ().

The issue will only sometimes occur within our automated test system.

We already updated the sdk to the latest version and tried removing all event handlers from the webview2 control and the CoreWebView2 instance before calling dispose on the windows forms web view2 control. We also made sure that each instance of our software will use its own UserDataFolder, as we were experiencing other issues when sharing the UserDataFolder through multiple instances.

However the problem persists.

Is there anything else we can try or anything we can do to analyze this issue?

win32u.dll!NtUserDestroyWindow()	Unknown
EmbeddedBrowserWebView.dll!00007ff9f9d3a813()	Unknown
EmbeddedBrowserWebView.dll!00007ff9f9d42f70()	Unknown
EmbeddedBrowserWebView.dll!00007ff9f9d6ed8f()	Unknown
EmbeddedBrowserWebView.dll!00007ff9f9d42aaf()	Unknown
[Managed to Native Transition]	
Microsoft.Web.WebView2.Core.dll!Microsoft.Web.WebView2.Core.CoreWebView2Controller.Close()	Unknown
Microsoft.Web.WebView2.WinForms.dll!Microsoft.Web.WebView2.WinForms.WebView2.UnsubscribeHandlersAndCloseController(bool browserCrashed)	Unknown
Microsoft.Web.WebView2.WinForms.dll!Microsoft.Web.WebView2.WinForms.WebView2.Dispose(bool disposing)	Unknown
System.dll!System.ComponentModel.Component.Dispose()	Unknown

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

1.0.2739.15

Framework

Winforms

Operating System

Windows 11

OS Version

No response

Repro steps

The problem is hard to manually reproduce, as it will only occur rarely on our automated test system

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

peh-87 avatar Sep 18 '24 12:09 peh-87

Hi @peh-87,

We understand that this issue is critical and significantly impacts your app's user experience. Could you please confirm if you are still encountering this problem? If so, could you provide details on how frequently it occurs?

sivMSFT avatar Nov 22 '24 12:11 sivMSFT

@sivMSFT we are also encountering this issue ~600+ times per day in our application while attempting to clean up our WebView. The stack trace is:

win32u.dll!NtUserDestroyWindow()
EmbeddedBrowserWebView.dll!embedded_browser_webview_current::internal::ClientWindowWin32::Close(void)
EmbeddedBrowserWebView.dll!embedded_browser_webview_current::Controller::CloseInternal(void)
EmbeddedBrowserWebView.dll!embedded_browser_webview_current::EmbeddedBrowserWebView::CloseInternal(long,bool,enum embedded_browser_webview::WebViewCloseReason)
EmbeddedBrowserWebView.dll!embedded_browser_webview_current::Controller::Close(void)

What is the suggested sequence for cleanly shutting down to avoid this issue? We are currently removing all event listeners, resetting WebView2 COM pointers, and then calling Close (all from the UI thread). We have not been able to reproduce this issue, but it does appear to be more likely to happen on lower-end machines with ~4-8GB of RAM.

This has been a persistent nagging issue with the WebView2 framework, and has been happening across multiple SDK/WebView versions.

This is a high priority issue for us, so please let us know if there is any additional information we can provide or experiments we can try to get this resolved.

Is this potentially related to: https://github.com/MicrosoftEdge/WebView2Feedback/issues/3140?

BenV avatar Aug 29 '25 17:08 BenV

@BenV just as info (I am working on the same product as @peh-87): We never really solved the issue. In the end, we simply disabled the WebView2 component in our automated test system, since it isn't critical for the product's main functionality. We never saw the issue "live" or on customer machines, probably because of the low probability.

Sedeniono avatar Aug 29 '25 20:08 Sedeniono

@BenV just as info (I am working on the same product as @peh-87): We never really solved the issue. In the end, we simply disabled the WebView2 component in our automated test system, since it isn't critical for the product's main functionality. We never saw the issue "live" or on customer machines, probably because of the low probability.

Thanks for the update! Yeah, we have a fairly high DAU which likely explains why we're seeing this out in the wild.

BenV avatar Aug 29 '25 21:08 BenV

I also met the hang issue, my webview2 version is 2.1.0.2957.106.

.  0  Id: 76d4.b98 Suspend: 0 Teb: 00000071`791f5000 Unfrozen
 # Child-SP          RetAddr           : Args to Child                                                           : Call Site
00 00000071`792fa638 00007fff`c6407833 : 00000000`001e0b54 00000000`00000000 00000071`792fa5f8 00000000`00000000 : win32u!NtUserDestroyWindow+0x14
01 00000071`792fa640 00007fff`c6410b97 : 000001aa`9f7c6540 000001aa`b4877840 00005800`00001260 00007fff`c6575de5 : EmbeddedBrowserWebView!embedded_browser_webview_current::internal::ClientWindowWin32::Close+0x43
02 00000071`792fa670 00007fff`c64404c7 : 00000000`00000000 00005800`0004ca40 00000000`00000000 00005800`00120158 : EmbeddedBrowserWebView!embedded_browser_webview_current::Controller::CloseInternal+0x4e3
03 00000071`792fa6f0 00007fff`c641065f : 000001aa`a4723758 00000000`00000014 0000a150`322e95e7 00000000`00000014 : EmbeddedBrowserWebView!embedded_browser_webview_current::EmbeddedBrowserWebView::CloseInternal+0x417
04 00000071`792fa7c0 00007fff`808a67af : 00000071`792fa860 000001aa`b00e4b10 00000000`00000000 000001aa`b00e4c90 : EmbeddedBrowserWebView!embedded_browser_webview_current::Controller::Close+0xaf
05 00000071`792fa800 00007fff`8089bc6b : 000001aa`b00e4c90 000001aa` ...

  17  Id: 76d4.6314 Suspend: 0 Teb: 00000071`7903e000 Unfrozen
 # Child-SP          RetAddr           : Args to Child                                                           : Call Site
00 00000071`7b0ff098 00007ff8`1e19d2cc : 00000001`00000000 aaaaaaaa`aaaaaa00 aaaaaaaa`aaaaaa00 aaaaaaaa`aaaaaa00 : ntdll!NtRemoveIoCompletion+0x14
01 00000071`7b0ff0a0 00007fff`c654b0a5 : 00000071`7b0ff250 00005800`00040660 00005800`000188a0 00000071`7b0ff170 : c_ieitfkja!GetQueuedCompletionStatus+0x6c
02 00000071`7b0ff100 00007fff`c654ac03 : 00000071`7b0ff250 00005800`00040660 00000071`7b0ff2b3 00007fff`c65e90bd : EmbeddedBrowserWebView!base::MessagePumpForIO::WaitForWork+0x125
03 00000071`7b0ff1b0 00007fff`c65d2a68 : 00000071`7b0ff380 0000a150`300ec0f7 00000000`9aec0701 00005800`000189c0 : EmbeddedBrowserWebView!base::MessagePumpForIO::DoRunLoop+0x173
04 00000071`7b0ff2d0 00007fff`c65ea301 : 00007ff8`20170000 00000071`7b0ff440 00000071`7b0ff448 00007fff`c663b16b : EmbeddedBrowserWebView!base::MessagePumpWin::Run+0x98
05 00000071`7b0ff350 00007fff`c65f0429 : 00000000`00000008 00007ff8`1ffc4970 00000000`00000000 00005800`000a8090 : EmbeddedBrowserWebView!base::sequence_manager::internal::ThreadControllerWithMessagePumpImpl::Run+0xd1
06 00000071`7b0ff3e0 00007fff`c65dde54 : 00005800`000188a8 00000000`00000000 00000071`7b0ff520 00007fff`c65f0314 : EmbeddedBrowserWebView!base::RunLoop::Run+0xa9
07 00000071`7b0ff4a0 00007fff`c65ddf9b : 00000071`7b0ff4e8 00005800`0003c5c0 00000071`7b0ff6d9 00007fff`c6575de5 : EmbeddedBrowserWebView!base::Thread::Run+0x44
08 00000071`7b0ff500 00007fff`c65cf696 : 00000071`7b0ff6a8 00000000`00000001 00000071`7b0ff6d9 00007ff8`1ffb2a26 : EmbeddedBrowserWebView!base::Thread::ThreadMain+0x11b
09 00000071`7b0ff580 00007ff8`1ffce8d7 : 00000020`00001000 00000000`01000000 0000b96b`3fe11332 00000000`00000000 : EmbeddedBrowserWebView!base::`anonymous namespace'::ThreadFunc+0x116
0a 00000071`7b0ff610 00007ff8`08cc74ce : 00000071`7b0ff760 000001aa`9b0f6770 00007ff8`08df2450 000001aa`9b116cf0 : d_xctxzv!BaseThreadInitThunk+0x17
0b 00000071`7b0ff640 00007ff8`08d16408 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : Protector64!DummyExport+0x1274e
0c 00000071`7b0ff740 00007ff8`20e5c34c : 00000000`00000000 00000000`00000000 000004f0`fffffb30 000004d0`fffffb30 : Protector64!DummyExport+0x61688
0d 00000071`7b0ff7c0 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x2c

czlitony avatar Nov 16 '25 15:11 czlitony