Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reentrance error in debug mode #3677

Closed
milemrkobrad opened this issue Aug 1, 2023 · 6 comments
Closed

reentrance error in debug mode #3677

milemrkobrad opened this issue Aug 1, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@milemrkobrad
Copy link

Description
When using method SynchronizationContext.Current.Send to open winform dialog from native app using js method globalThis.chrome.webview.hostObjects.dotnet.HostMethodName(JSON.stringify(objectToPass)), if dialog box is not closed, after aprox. 20 seconds app crashes with no error message. After turning on "Enable native code debugging" option in project properties I get error message:

Running a message loop synchronously in an event handler in Webview can cause reentrancy issue. Please refer to https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/threading-model#re-entrancy for more information about threading model in WebView2 and how to enable native code debugging for this scenario.

This only occurs in debug mode.
I am aware that there exists async method "Post" but I need sync method, because I am waiting dialog result (user action).

Version
SDK: 1.0.1901.177
Runtime: 115.0.1901.188
Framework: WinForms .NET Framework 4.8
OS: Win 10 Enterprise Built 19045
Regression
Was this working before but has regressed? no

@milemrkobrad milemrkobrad added the bug Something isn't working label Aug 1, 2023
@novac42
Copy link
Contributor

novac42 commented Aug 2, 2023

Thanks for reporting the issue and sorry you are running into it. I've assigned this to a dev who can help follow up on this.

@Shangminx
Copy link
Contributor

@milemrkobrad , Could you help to provide your project code. It's useful for us to repro this issue.

@milemrkobrad
Copy link
Author

milemrkobrad commented Aug 10, 2023

Webview2TestProject.zip
Hi, I attached small example project to help repro this issue. Once you run (run with debugging) this project, OpenFileDialog will pop up and then you should leave it opened for approx. 25 seconds. Exception message should occur.
I also attached images showing exception messages. Please note that exception message has changed since last comment. Now I get "EmbeddedBrowserWebView.dll.pdb not loaded" instead reentrance error message. Source code remained the same.
This is probably due to the fact that my webview2 runtime version is updated to 115.0.1901.200
s1
s2

@Shangminx
Copy link
Contributor

Hi @milemrkobrad , I repro this issue locally. I found that the exception doesn't crush the process. It just triggers a breakpoint. So In release mode nothing will happen after aprox 20s. Just in debug mode, for some debugger reason it would throw cuz timeout.
I think you can use SynchronizationContext.Current.Post and deferral like this Does this help you?

@milemrkobrad
Copy link
Author

milemrkobrad commented Aug 28, 2023

could not make it work using deferral , but this way, using TaskCompletionSource class seems to work fine:

public async Task OpenDlgSyncCtxPost(string jsonStr)
{
var tcs = new TaskCompletionSource();

  SynchronizationContext.Current.Post(_ =>
  {
      string result = OpenDlg(jsonStr);
      tcs.SetResult(result);
  }, null);

  return await tcs.Task;

}

@victorhuangwq
Copy link
Collaborator

@milemrkobrad seems like you have found a solution? In that case I will be closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants