-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc(logging): add hanging request logging in driver #6297
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -469,6 +469,7 @@ class Driver { | |
* @private | ||
*/ | ||
_waitForNetworkIdle(networkQuietThresholdMs) { | ||
let hasDCLFired = false; | ||
/** @type {NodeJS.Timer|undefined} */ | ||
let idleTimeout; | ||
/** @type {(() => void)} */ | ||
|
@@ -499,19 +500,45 @@ class Driver { | |
}; | ||
|
||
const domContentLoadedListener = () => { | ||
hasDCLFired = true; | ||
if (networkStatusMonitor.is2Idle()) { | ||
onIdle(); | ||
} else { | ||
onBusy(); | ||
} | ||
}; | ||
|
||
// We frequently need to debug why LH is still waiting for the page. | ||
// This listener is added to all network events to verbosely log what URLs we're waiting on. | ||
const logStatus = () => { | ||
if (!hasDCLFired) { | ||
log.verbose('Driver', 'Waiting on DomContentLoaded'); | ||
return; | ||
} | ||
|
||
const inflightRecords = networkStatusMonitor.getInflightRecords(); | ||
// If there are more than 20 inflight requests, load is still in full swing. | ||
// Wait until it calms down a bit to be a little less spammy. | ||
if (inflightRecords.length < 20) { | ||
for (const record of inflightRecords) { | ||
log.verbose('Driver', `Waiting on ${record.url.slice(0, 120)} to finish`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probably remove all the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I still found them helpful to track exactly when the idle timeout would be started and cancelled (and to break up the repeated sets of URLs when filtering out the '<= event:verbose' events which are the real crazy chatty ones!), but agreed the wall of them every time we call |
||
} | ||
} | ||
}; | ||
|
||
networkStatusMonitor.on('requeststarted', logStatus); | ||
networkStatusMonitor.on('requestloaded', logStatus); | ||
networkStatusMonitor.on('network-2-busy', logStatus); | ||
|
||
this.once('Page.domContentEventFired', domContentLoadedListener); | ||
cancel = () => { | ||
idleTimeout && clearTimeout(idleTimeout); | ||
this.off('Page.domContentEventFired', domContentLoadedListener); | ||
networkStatusMonitor.removeListener('network-2-busy', onBusy); | ||
networkStatusMonitor.removeListener('network-2-idle', onIdle); | ||
networkStatusMonitor.removeListener('requeststarted', logStatus); | ||
networkStatusMonitor.removeListener('requestloaded', logStatus); | ||
networkStatusMonitor.removeListener('network-2-busy', logStatus); | ||
}; | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've been a little concerned about the length of our
NetworkRecord
callbacks. I was seeing 1+ms for some while doing some OYB profiling a while back, and there are a lot of callbacks.Can we detect whether or not we're in
verbose
mode before doing any of this work? Short ofsettings
in here or changing lighthouse-logger again, I'm not sure there is, sadly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this and another lighthouse-logger change, I want one level in between verbose and default (debug or info perhaps?) that doesn't contain every protocol message
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Yah not showing events from Network domain would be my number one request.