-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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(driver): add timeout to getRequestContent #4718
Conversation
lighthouse-core/gather/driver.js
Outdated
return new Promise((resolve, reject) => { | ||
// If this takes more than 2s, reject the Promise. | ||
const err = new Error('Fetching resource content has exceeded the allotted time of 2s'); | ||
const asyncTimeout = setTimeout((_ => reject(err)), 2000); |
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'd be cool going down to 1s too to keep things moving
lighthouse-core/gather/driver.js
Outdated
}).then(result => result.body); | ||
return new Promise((resolve, reject) => { | ||
// If this takes more than 2s, reject the Promise. | ||
const err = new Error('Fetching resource content has exceeded the allotted time of 2s'); |
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.
should we try to give this thing an error code and be consistent about timeout stuff moving forward?
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.
very nice sleuthing 👏
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.
LGTM
lighthouse-core/gather/driver.js
Outdated
// Ignoring result.base64Encoded, which indicates if body is already encoded | ||
}).then(result => result.body); | ||
return new Promise((resolve, reject) => { | ||
// If this takes more than 2s, reject the Promise. |
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.
maybe add a note with link back to your investigation for why this method in particular can be problematic?
ae6ef54
to
85ee3a7
Compare
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.
two last things
return driverStub.getRequestContent(0, MAX_WAIT_FOR_PROTOCOL).then(_ => { | ||
assert.ok(false, 'long-running getRequestContent supposed to reject'); | ||
}).catch(e => { | ||
assert.equal(e.code, 'REQUEST_CONTENT_TIMEOUT'); |
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.
will the above assert message get eaten by this comparison? could also do the two function then()
return driverStub.getRequestContent(0).then(value => {
assert.ok(false, 'long-running getRequestContent supposed to reject');
}, e => {
assert.equal(e.code, 'REQUEST_CONTENT_TIMEOUT');
});
lighthouse-core/gather/driver.js
Outdated
@@ -714,13 +715,25 @@ class Driver { | |||
/** | |||
* Return the body of the response with the given ID. | |||
* @param {string} requestId | |||
* @param {?number} timeout |
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.
{number=}
fixes #4258
I was able to repro on all the URLs mentioned in the ticket:
Network.getResponseBody
is taking >5s to respond when provided particular requestIds. But it's quite odd. If i have devtools open at the same time, the devtools frontend can issue the exact same protocol method with the same requestId and it has no problem. (and apparently devtools and CLI also have no problem)So this is particular to the extension.. sort of.
Update: the root bug appears to be an encoding issue in how the extension handles
chrome.debugger
payloads. Below is a bunch of details that supports that argument:here's the 4 scripts that will reliably cause a problem:
I believe these files all have some characters in common that are mishandled somewhere in encoding.
I ran this across these 4 files:
And they all have in common some fairly high codepoints:
They all have in common 65534 or 65535.
And... check this out. Run this in any DevTools console:
Now take that resulting string, copy/paste it back and try to evaluate it. DevTools won't. :)
So, since this appears to be rather an involved bug. My easy workaround is to add a 2s timeout.
I did observe a 300ms successful response time for this method on a fairly big file so 2000ms seems an OK maximum.