Skip to content

fix(frame): don't miss a load state fired while the wait is being set up - #3400

Closed
feiyun0112 wants to merge 1 commit into
microsoft:mainfrom
feiyun0112:issues/3399
Closed

feiyun0112 wants to merge 1 commit into
microsoft:mainfrom
feiyun0112:issues/3399

Conversation

@feiyun0112

Copy link
Copy Markdown
Contributor

WaitForLoadStateAsync inspected _loadStates and only then subscribed to the LoadState event. OnLoadState is dispatched on the protocol thread, so a state recorded between those two steps was added to _loadStates but its event was never observed by the waiter, which then only ever ended with a timeout. This is what made WaitForURLAsync(WaitUntil = Load) intermittently time out on a page that was already fully loaded.

Subscribe first and inspect the recorded state afterwards, so that an event fired concurrently is either caught by the handler or already visible in _loadStates. _loadStates is now guarded by a lock, since it is written on the protocol thread and read on the caller's thread.

WaitForNavigationAsync had the same check-then-subscribe pair; both now share a single helper.

fixes #3399

`WaitForLoadStateAsync` inspected `_loadStates` and only then subscribed to the
`LoadState` event. `OnLoadState` is dispatched on the protocol thread, so a state
recorded between those two steps was added to `_loadStates` but its event was
never observed by the waiter, which then only ever ended with a timeout. This is
what made `WaitForURLAsync(WaitUntil = Load)` intermittently time out on a page
that was already fully loaded.

Subscribe first and inspect the recorded state afterwards, so that an event fired
concurrently is either caught by the handler or already visible in `_loadStates`.
`_loadStates` is now guarded by a lock, since it is written on the protocol
thread and read on the caller's thread.

`WaitForNavigationAsync` had the same check-then-subscribe pair; both now share a
single helper.

fixes microsoft#3399
@dgozman

Copy link
Copy Markdown
Collaborator

Closing in favor of #3453.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: WaitForURLAsync(WaitUntil = Load) intermittently times out although load has already fired (readyState === 'complete')

2 participants