fix(core): fix race condition in waitForFunctionExpression()#41706
Merged
Conversation
hbenl
commented
Jul 9, 2026
This comment has been minimized.
This comment has been minimized.
Member
|
@dgozman can you have a look? |
dgozman
reviewed
Jul 9, 2026
| const context = world === 'main' ? await progress.race(this.mainContext()) : await progress.race(this.utilityContext()); | ||
| const injectedScript = await progress.race(context.injectedScript()); | ||
| const handle = await progress.race(injectedScript.evaluateHandle((injected, { expression, isFunction, polling, arg }) => { | ||
| const handle = await injectedScript.evaluateHandle((injected, { expression, isFunction, polling, arg }) => { |
Collaborator
There was a problem hiding this comment.
I think raceUncancellableOperationWithCleanup is the way. We have to race this evaluateHandle call, otherwise it may stall forever due to a stalling navigation.
hbenl
force-pushed
the
fix-waitforfunction
branch
from
July 10, 2026 13:53
c1cc0cc to
1cffa8d
Compare
Contributor
Test results for "MCP"7760 passed, 1249 skipped Merge workflow run. |
Contributor
Test results for "tests 1"4 flaky49520 passed, 1161 skipped Merge workflow run. |
yury-s
approved these changes
Jul 10, 2026
dgozman
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into a subtle race condition in
Frame.waitForFunctionExpression()(see #41637 (comment)):If the operation is aborted during
injectedScript.evaluateHandle()(after it sent the evaluation to the browser but before it receives the result), the loop that it sets up in the browser is never aborted.This PR fixes the issue by removing the
progress.race()wrapper aroundinjectedScript.evaluateHandle()and checkingprogress.signal.abortedafterwards instead, ensuring that the catch block that aborts the loop is executed in this case.I thought about using
raceUncancellableOperationWithCleanup()instead but it doesn't await the cleanup function before throwing.