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: handle invalid network timing data #6780

Merged
merged 2 commits into from
Dec 13, 2018
Merged

Conversation

patrickhulce
Copy link
Collaborator

Summary
In LR, the timing object can be defined but have no valid data (requestTime: 0, receiveHeadersEnd: -1). This was unexpected and was causing problems later on down the chain for lantern.

Masking the problem was the fact that the rootNode of the lantern graph was trying to pick the earliest network request but was breaking ties by choosing the last network record in the array. When the requestTimes were 0, it just ended up picking the last one and losing the real root node. This PR also adds some sanity checks around that to make sure we'd fail earlier about those unexpected cases.

Related Issues/PRs
fixes #6378

Copy link
Member

@brendankenny brendankenny left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -272,6 +272,9 @@ module.exports = class NetworkRequest {
* @param {LH.Crdp.Network.ResourceTiming} timing
*/
_recomputeTimesWithResourceTiming(timing) {
// Don't recompute times if the data is invalid. RequestTime should always be a thread timestamp.
// If we don't have receiveHeadersEnd, we really don't have more accurate data.
if (timing.requestTime === 0 || timing.receiveHeadersEnd === -1) return;
Copy link
Member

Choose a reason for hiding this comment

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

ha, I believe this would have saved me a lot of time figuring out how to generate the right network request events in #6171

@@ -269,8 +269,11 @@ class PageDependencyGraph {
const networkNodeOutput = PageDependencyGraph.getNetworkNodeOutput(networkRecords);
const cpuNodes = PageDependencyGraph.getCPUNodes(traceOfTab);

const rootRequest = networkRecords.reduce((min, r) => (min.startTime < r.startTime ? min : r));
// The root request is the earliest network request, using position in networkRecords array to break ties.
Copy link
Member

Choose a reason for hiding this comment

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

best comment

@@ -269,8 +269,11 @@ class PageDependencyGraph {
const networkNodeOutput = PageDependencyGraph.getNetworkNodeOutput(networkRecords);
const cpuNodes = PageDependencyGraph.getCPUNodes(traceOfTab);

const rootRequest = networkRecords.reduce((min, r) => (min.startTime < r.startTime ? min : r));
// The root request is the earliest network request, using position in networkRecords array to break ties.
const rootRequest = networkRecords.reduce((min, r) => (r.startTime < min.startTime ? r : min));
Copy link
Member

Choose a reason for hiding this comment

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

might be overkill, but should we pull this out into another method on NetworkAnalyzer like findMainDocument? I can see it usable by others (if they remember it's there).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd want to shift consumers to be using the graph as the source of truth, so hopefully no one else needs to compute this too? :)

@patrickhulce patrickhulce merged commit 705741e into master Dec 13, 2018
@patrickhulce patrickhulce deleted the fix_graph_cycle branch December 13, 2018 14:37
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.

Invalid dependency graph created, cycle detected
2 participants