[BUG] (RunAnd)WaitFor(Request/Response/RequestFinished)Async methods ignore exceptions thrown by action
See original GitHub issueContext:
- Playwright Version: 1.31.0
- Operating System: any (Windows, Linux, MacOS)
- .NET version: .NET 7
- Browser: Edge (Chromium)
Code Snippet
using System.Threading.Tasks;
using Microsoft.Playwright;
class Program
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
var options = new() { Predicate = r => true };
var wait = page.RunAndWaitForRequestFinishedAsync(()=>throw new Exception(), options)
await wait;
// dead waiting - only timeout and no original exception
}
}
Description
(RunAnd)WaitFor(Request/Response/RequestFinished)Async
method family are implemented by InnerWaitForEventAsync
in such a way that ignores exceptions thrown by action. If the action ends up in Failed state (the resulting Task
has failed because of some Exception
) the actual Wait inside Playwright doesn’t inspect the exception and the failed path ends up in timeout state.
The Waiter makes that happen by throwing TimeoutException
.
The actual BUG is the fact that the Waiter still waits for some request to filter - but the action that was supposed to trigger some chit-chat that would caused some Requests has thrown in this scenario.
Action throwing -> Exception captured and set on a transient task in WhenAll -> the Waiter waits until timeout.
Secondly there is no CancellationToken
to cancel Wait when a caller of (...)WaitFor(...)
has some knowledge that the wait became pointless. There is some meaningful amount of time that can be recovered by providing a cancellation here.
So, to summarize:
- Exceptions from action are missing
- No cancellation option for Waits
The exact places in code:
playwright-dotnet\src\Playwright\Core\Page.cs : 435-438
playwright-dotnet\src\Playwright\Core\Waiter.cs - whole implementation - there should be a RejectOnCancellation
or something along those lines.
Patched by: https://github.com/microsoft/playwright-dotnet/pull/2535
Issue Analytics
- State:
- Created 6 months ago
- Comments:6 (6 by maintainers)
Thanks!
PR approved, awaiting merge and release.