-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[🐛 Bug]: "System.IO.IOException : Cannot access a closed stream" when disposing DevToolsSession #14466
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
Comments
@arnonax-tr, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
This issue is obvious. network.RequestPaused += async (_, args) =>
{
await network.ContinueRequestWithoutModification(args.RequestData);
} which may lead to It happens because your async event handler is invoked in background, while main execution program is continuing. And there is a chance that main execution flow disposes driver earlier than your This situation is fixed in new BiDi approach (#14318). I have no ideas how to fix it. Probably making your event handler sync can help (at least please try): network.RequestPaused += (_, args) =>
{
Task.Run(async () => await network.ContinueRequestWithoutModification(args.RequestData));
} EDITED: |
I don't think so. That's exactly the reason I added the |
Regarding the BiDi approach: do you have an ETA for when it will be available? Also I'll be grateful if you can provide an example of how my code should look like with that approach. |
Your event handler is async void, selenium invokes (actually schedules your delegate in TaskScheduler to be invoked), and we don't know when exactly your handler is actually invoked. Moreover, in selenium we really fire and forget event handlers. This is design issue, which may lead to unexpected behavior in race conditions. This design issue is addressed in BiDi implementation (or at least should be addressed). No ETA, PR is under review. |
I saw that the Bidi PR was merged to trunk. Does it mean that it will be available in the next release? Also, are there examples or documentation on how to use it for capturing and manipulating network traffic? |
There is nightly builds you can try right now: https://github.com/SeleniumHQ/selenium/pkgs/nuget/Selenium.WebDriver Documentation is not available yet, hopefully the following code may help you to get started: var context = await driver.AsBidirectionalContextAsync();
await context.Network.OnBeforeRequestSentAsync(e => Console.WriteLine(e));
await context.NavigateAsync("https://selenium.dev", new() { Wait = ReadinessState.Complete });
await context.Network.InterceptRequestAsync(async e => await e.Request.Request.FailAsync()); |
I will close this as the issue has not had any more activity. |
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs. |
Uh oh!
There was an error while loading. Please reload this page.
What happened?
This bug happens pretty rarely, but it does. I ran the following test with
[Repeat(1000)]
to reproduce it:And I got the following exception:
How can we reproduce the issue?
Relevant log output
Operating System
Windows 11
Selenium version
C# 11 (dotnet 8), Selenium.WebDriver 4.23.0
What are the browser(s) and version(s) where you see this issue?
Chrome 128
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver 128.0.6613.8600
Are you using Selenium Grid?
No response
The text was updated successfully, but these errors were encountered: