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

[🐛 Bug]: Entire application crash in case of unhandled exception in async void method #12480

Closed
nvborisenko opened this issue Aug 2, 2023 · 5 comments · Fixed by #12486
Closed

Comments

@nvborisenko
Copy link
Member

What happened?

Application is crashed.

How can we reproduce the issue?

Open `youtube.com` with enabled network monitoring.


var net = driver.Manage().Network;

        net.NetworkRequestSent += (sender, e) =>
        {
            //Console.WriteLine(e.RequestUrl);
        };

Relevant log output

Running selected tests in D:\Temp\aaa\bin\Debug\net7.0\aaa.dll
   NUnit3TestExecutor discovered 1 of 1 NUnit test cases using Current Discovery mode, Non-Explicit run
The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at aaa.UnitTest1.<>c__DisplayClass0_0.<Test1>b__2(Object sender, NetworkResponseReceivedEventArgs e) in D:\Temp\aaa\UnitTest1.cs:line 31
   at OpenQA.Selenium.NetworkManager.OnResponsePaused(Object sender, ResponsePausedEventArgs e)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.QueueUserWorkItemCallback.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()


### Operating System

any

### Selenium version

any

### What are the browser(s) and version(s) where you see this issue?

any

### What are the browser driver(s) and version(s) where you see this issue?

any

### Are you using Selenium Grid?

_No response_
@github-actions
Copy link

github-actions bot commented Aug 2, 2023

@nvborisenko, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@nvborisenko
Copy link
Member Author

It happens because of async void as event handler: https://github.com/SeleniumHQ/selenium/blob/fbfa5d26ce96ca067d62b6921915e640498e3b09/dotnet/src/webdriver/NetworkManager.cs#L215C9-L215C9

We should refactor it to async Task or just void.

@diemol
Copy link
Member

diemol commented Aug 3, 2023

Thank you for reporting this and pointing out the issue. Which option would be better?

@nvborisenko
Copy link
Member Author

async Task is better, it allows us use await in the body. But changing method signature might be a breaking change (hopefully no, seems it's not public).

Otherwise plan B: just void and changing all awaits to Task.Run().GetAwaiter().GetResult().

Copy link

github-actions bot commented Dec 8, 2023

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants