fix(screenshotter): race cleanup against progress to honor timeout#40901
Open
Skn0tt wants to merge 1 commit into
Open
fix(screenshotter): race cleanup against progress to honor timeout#40901Skn0tt wants to merge 1 commit into
Skn0tt wants to merge 1 commit into
Conversation
The `finally` blocks in `screenshotPage` and `screenshotElement` awaited
`_restorePageAfterScreenshot()` without racing against `progress`. If
the renderer's event loop was blocked (e.g. busy JS loop),
`nonStallingEvaluateInExistingContext` would hang indefinitely because
it only races against navigation / open dialogs, not against an
arbitrary timeout — swallowing the timeout error and hanging the call.
Wrap both cleanups in `progress.race(...).catch(() => {})`. The
`.catch` is required to avoid masking an in-flight error from the
`try` block with the abort error from the race.
Fixes: microsoft#36702
dgozman
reviewed
May 19, 2026
Collaborator
dgozman
left a comment
There was a problem hiding this comment.
I am not sure this is a good solution. We'll end up in a situation where we were able to set things up, then we were not able to tear things down, and now the page is kind of broken.
It seems like we were not able to _preparePageForScreenshot() in this case as well though. If so, we don't have to do any cleanup as well. Perhaps that would be a better fix?
Contributor
Test results for "MCP"7116 passed, 1113 skipped Merge workflow run. |
Contributor
Test results for "tests 1"3 flaky42016 passed, 850 skipped Merge workflow run. |
Member
Author
|
In this particular test case, the prepare succeeds because of the 10ms timeout until the spin begins. And looking at |
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.
Cleanup in
screenshotPage/screenshotElementfinallyblocks was not raced againstprogress. When the renderer's event loop is blocked,nonStallingEvaluateInExistingContextonly races against navigation / open dialogs — not arbitrary timeouts — so cleanup would hang indefinitely and swallow the timeout error.Fixes #36702