Run continuation asynchronously in context of events#3256
Run continuation asynchronously in context of events#3256nvborisenko wants to merge 20 commits intomicrosoft:mainfrom
Conversation
|
Apologies for the inquiry, but after a month without activity, I'm concerned I may have done something improperly. @mxschmitt, if you happen to know the cause, I would be very grateful for a hint. Thank you. |
|
Hi Nikolay, sorry for not taking a look earlier. I'll ask our colleague Dima for a review, but it'll take a little longer due to holidays. |
Skn0tt
left a comment
There was a problem hiding this comment.
I did some digging on the ramifications of this options, and it seems like a safe change for us. The only negative implication is a slight overhead since the continuation now needs to wait for the scheduler, but that microsecond impact is neglegible given we're dealing with slow browsers.
My understanding of DotNet's async scheduling is limited, so please take another look @dgozman.
|
It is absolutely safe, moreover it is recommended for libraries to prevent deadlocks I demonstrated in the original issue. |
dgozman
left a comment
There was a problem hiding this comment.
The fix looks good to me. Let's add a test though, to avoid regressing this behavior.
|
Honestly, I am not sure how to test it properly. Please advise. |
Add a test next to this one that follows your repro code from this issue. I'd recommend to use this test page, so that you can wait for |
|
@microsoft-github-policy-service agree |
|
Added test, verified locally - it blocks in |
|
CI is unstable with the message |
|
Thank you for the PR! |
|
Hmm, CI is still failing after trying again. @nvborisenko, could you merge in main to see if this is also true on Playwright 1.58? Maybe it was fixed upstream. |
|
Stabilized CI build. Actually original simple changes/improvements revealed hidden race conditions. Then I made some changes to "fix" it, but I am afraid some of these "improvements" might be unnecessary (I don't fully understand what I did). I will try to identify whether my changes are actually necessary to clean up this PR at least. Thank you for your support. |
Skn0tt
left a comment
There was a problem hiding this comment.
Thanks for looking into it! I'll mark this as "request changes" to prevent anybody from accidentally merging while we haven't re-reviewed it.
This PR make Playwright events waiter more friendly with sync-over-async pattern.
Issue
This piece of code demonstrates deadlock. Real code, you can run it (I ran it in NUnit).
Here
GetAwaiter().GetResult()is blocked. We understand that it is anti-pattern,sync-over-async. To fix it we can addawait Task.Yield(). But what if Playwright can be more friendly for dummy users like me?Solution?
This PR allows tasks continuations asynchronously. Now the code above just works.