Bug 1189425 - Remove unparsable pings from the disk. r=vladan

This commit is contained in:
Georg Fritzsche 2015-08-18 14:15:47 +02:00
parent 182853ec0e
commit d7b7df9ee3
2 changed files with 12 additions and 2 deletions

View File

@ -1257,12 +1257,14 @@ let TelemetryStorageImpl = {
ping = yield this.loadPingFile(info.path, false);
} catch(e) {
// If we failed to load the ping, check what happened and update the histogram.
// Then propagate the rejection.
if (e instanceof PingReadError) {
Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_READ").add();
} else if (e instanceof PingParseError) {
Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_PARSE").add();
}
// Remove the ping from the cache, so we don't try to load it again.
this._pendingPings.delete(id);
// Then propagate the rejection.
throw e;
};
@ -1442,8 +1444,9 @@ let TelemetryStorageImpl = {
try {
array = yield OS.File.read(aFilePath, options);
} catch(e) {
this._log.trace("loadPingfile - unreadable ping " + aFilePath, e);
throw new PingReadError(e.message);
};
}
let decoder = new TextDecoder();
let string = decoder.decode(array);
@ -1455,6 +1458,10 @@ let TelemetryStorageImpl = {
ping.payload = JSON.parse(ping.payload);
}
} catch (e) {
this._log.trace("loadPingfile - unparseable ping " + aFilePath, e);
yield OS.File.remove(aFilePath).catch((ex) => {
this._log.error("loadPingFile - failed removing unparseable ping file", ex);
});
throw new PingParseError(e.message);
}

View File

@ -316,6 +316,9 @@ add_task(function* test_corrupted_pending_pings() {
h = Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_PARSE").snapshot();
Assert.equal(h.sum, 1, "Telemetry must report a pending ping parse failure");
let exists = yield OS.File.exists(getSavePathForPingId(pendingPingId));
Assert.ok(!exists, "The unparseable ping should have been removed");
yield clearPendingPings();
});