Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: don't use failed network requests as potential initiators #14819

Merged
merged 2 commits into from
Feb 22, 2023

Conversation

brendankenny
Copy link
Member

Ran into a weird case where a page refreshed itself via JS, Chrome fired and quickly cancelled (in less than a millisecond) a request for the page, then completed an h3 request for it. This could match the description of how Chrome will optimistically make h3 requests in parallel to an h2 request, but AFAIK that should be invisible outside the network stack and we'd be seeing a whole lot more failed requests for any h3 sites if it were observable.

Regardless of the reason, having two requests for the page precede the successful h3 request makes the JS stack initiator URL ambiguous and so an initiatorRequest isn't set. A request that failed can't be the initiator, so instead it's one more case that can be ruled out.


Unfortunately, requiring finished and failed to be set exposed the fragility of a few older tests that were manually specifying devtoolsLog messages. Each request in those tests would require an additional Network.loadingFinished message for them to be marked finished, so it was easier (and considerably more concise) to switch the tests over to networkRecordsToDevtoolsLog. I've ensured they generate the same network requests and they hit the same checks in network-recorder code, but it does make this PR more of a pain. Those changes are separated into the second commit to make them slightly easier to review.

@brendankenny brendankenny requested a review from a team as a code owner February 22, 2023 00:59
@brendankenny brendankenny requested review from adamraine and removed request for a team February 22, 2023 00:59
Comment on lines -304 to -305
// unlikely to occur in practice. In particular, the initiator's timestamp
// is after the initiated's timestamp.
Copy link
Member Author

@brendankenny brendankenny Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT this timestamp comment was a c/p error (it was never true for this test or the next one)

@@ -695,74 +529,123 @@ describe('network recorder', function() {
expect(imageRequest.initiatorRequest).toBe(preloadRequest);
});

it('should not set initiator when ambiguous', () => {
const logs = [
it('should discard failed initiators', () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new test from the network requests of the page I was testing

Comment on lines +342 to +343
timestamp: normalizedTiming.networkEndTime / 1000,
type: networkRecord.resourceType || undefined,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently we didn't have any failed requests going through networkRecordsToDevtoolsLog (at least with verification on) because the missing / 1000 would have caused any to fail the roundtrip test. Fixed the timing, added support for failed resourceTypes for good measure (needed for the document redirect chain debugging I was doing), and added the line to network-records-to-devtools-log-test.js to ensure that path is exercised going forwards

const [rootDoc, failedDoc, refreshDoc] = records;
expect(rootDoc.initiatorRequest).toBe(undefined);
expect(failedDoc.initiatorRequest).toBe(rootDoc);
expect(refreshDoc.initiatorRequest).toBe(rootDoc);
Copy link
Member Author

@brendankenny brendankenny Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

without this change, this line would need to be
expect(refreshDoc.initiatorRequest).toBe(undefined) because it was unable to tell if rootDoc or failedDoc should be the initiator.

@devtools-bot devtools-bot merged commit 4ef4cfb into main Feb 22, 2023
@devtools-bot devtools-bot deleted the failed-initiators branch February 22, 2023 22:14
@ftservice ftservice linked an issue Feb 28, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Phone
3 participants