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(response-compression): graceful recovery #5578

Merged
merged 1 commit into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class ResponsesAreCompressed extends ByteEfficiencyAudit {
/** @type {Array<LH.Audit.ByteEfficiencyItem>} */
const items = [];
uncompressedResponses.forEach(record => {
// Ignore invalid GZIP size values (undefined, NaN, 0, -n, etc)
if (!record.gzipSize || record.gzipSize < 0) return;

const originalSize = record.resourceSize;
const gzipSize = record.gzipSize;
const gzipSavings = originalSize - gzipSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
'use strict';

const Gatherer = require('../gatherer');
const URL = require('../../../lib/url-shim');
const Sentry = require('../../../lib/sentry');
const NetworkRequest = require('../../../lib/network-request');
const gzip = require('zlib').gzip;

Expand Down Expand Up @@ -99,6 +101,16 @@ class ResponseCompression extends Gatherer {
resolve(record);
});
});
}).catch(err => {
// @ts-ignore TODO(bckenny): Sentry type checking
Sentry.captureException(err, {
tags: {gatherer: 'ResponseCompression'},
extra: {url: URL.elideDataURI(record.url)},
level: 'warning',
});

record.gzipSize = undefined;
return record;
});
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ describe('Optimized responses', () => {
});
});

it('recovers from driver errors', () => {
options.driver.getRequestContent = () => Promise.reject(new Error('Failed'));
return responseCompression.afterPass(options, createNetworkRequests(traceData))
.then(artifact => {
assert.equal(artifact.length, 2);
assert.equal(artifact[0].resourceSize, 6);
assert.equal(artifact[0].gzipSize, undefined);
});
});

it('ignores responses from installed Chrome extensions', () => {
const traceData = {
networkRecords: [
Expand Down
2 changes: 1 addition & 1 deletion typings/artifacts.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ declare global {
/** HTML snippets from any password inputs that prevent pasting. */
PasswordInputsWithPreventedPaste: {snippet: string}[];
/** Size info of all network records sent without compression and their size after gzipping. */
ResponseCompression: {requestId: string, url: string, mimeType: string, transferSize: number, resourceSize: number, gzipSize: number}[];
ResponseCompression: {requestId: string, url: string, mimeType: string, transferSize: number, resourceSize: number, gzipSize?: number}[];
/** Information on fetching and the content of the /robots.txt file. */
RobotsTxt: {status: number|null, content: string|null};
/** Set of exceptions thrown during page load. */
Expand Down