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 started investigating why PageGotoTests were failing sometimes with NullReferenceException (e.g. https://github.com/hardkoded/puppeteer-sharp/actions/runs/5257640661/jobs/9500723964).
I found that, when the tests fails, the Response object wasn't initialized yet in the test's thread, but another thread was concurrently processing a message that would initialize it. More investigation indicated that the timing and order of two messages would determine if the test passed/failed.
Page.navigate
message is sent to initiate the navigation. This message awaits forNewDocumentNavigationTask
from LifecycleWatcher.Network.responseReceived
andNetwork.responseReceivedExtraInfo
, are received as a result of the navigation. It seems thatNetwork.responseReceived
is always delivered before thePage.navigate
resolves. But the order that the two messages are delivered varies with each test execution.Network.responseReceivedExtraInfo
is delivered beforeNetwork.responseReceived
, the code inNetworkManager.OnResponseReceived
is able to find theextraInfo
and proceeds to executeEmitResponseEvent()
which sets the Response object.Network.responseReceived
is delivered beforeNetwork.responseReceivedExtraInfo
, the execution ofNetworkManager.OnResponseReceived
does not find theextraInfo
object and queues the response event. In this state, theNewDocumentNavigationTask
can resolve and continue the test execution before the Response object is set.I compared the relevant code with upstream, and found some differences that were committed in puppeteer/puppeteer#8717. My understanding is that the
_newDocumentNavigation
flag was being set too early by a same-document navigation (somehow related to beforeunload events), and thus causing theNewDocumentNavigationTask
to resolve before it should have. I am still investigating if that is sufficient to make sure the Response object is set.I also found that ShouldWorkWhenNavigatingTo404 was failing consistently when executed in headful mode, and this had been fixed upstream by puppeteer/puppeteer#9577.