Bug 1929109 - Better handle I/O issues that may be triggered while recording crashes r=afranchuk

Differential Revision: https://phabricator.services.mozilla.com/D229501
This commit is contained in:
Gabriele Svelto
2024-11-19 17:41:12 +00:00
parent 8424c52dc1
commit 17f11234a4
2 changed files with 45 additions and 28 deletions

View File

@@ -46,10 +46,13 @@ export var makeFakeAppDir = function () {
pendingD.append("pending");
let submittedD = reportsD.clone();
submittedD.append("submitted");
let eventsD = reportsD.clone();
eventsD.append("events");
makeDir(reportsD);
makeDir(pendingD);
makeDir(submittedD);
makeDir(eventsD);
let provider = {
getFile(prop, persistent) {
@@ -58,7 +61,10 @@ export var makeFakeAppDir = function () {
return appD.clone();
}
throw Components.Exception("", Cr.NS_ERROR_FAILURE);
throw Components.Exception(
"failed to get file: " + prop,
Cr.NS_ERROR_FAILURE
);
},
QueryInterace(iid) {

View File

@@ -784,7 +784,7 @@ CrashManager.prototype = Object.freeze({
* Submit a Glean crash ping with the given parameters.
*
* @param {string} reason - the reason for the crash ping, one of: "crash", "event_found"
* @param {string} type - the process type (from {@link processTypes})
* @param {string} process_type - the process type (from {@link processTypes})
* @param {DateTime} date - the time of the crash (or the closest time after it)
* @param {string} minidumpHash - the hash of the minidump file, if any
* @param {object} stackTraces - the object containing stack trace information
@@ -792,7 +792,7 @@ CrashManager.prototype = Object.freeze({
*/
_submitGleanCrashPing(
reason,
type,
process_type,
date,
minidumpHash,
stackTraces,
@@ -810,7 +810,7 @@ CrashManager.prototype = Object.freeze({
}
}
Glean.crash.processType.set(type);
Glean.crash.processType.set(process_type);
Glean.crash.time.set(date.getTime() * 1000);
Glean.crash.minidumpSha256Hash.set(minidumpHash);
@@ -1098,9 +1098,11 @@ CrashManager.prototype = Object.freeze({
*/
_getDirectoryEntries(path, re) {
return (async function () {
let children = await IOUtils.getChildren(path);
let entries = [];
try {
let children = await IOUtils.getChildren(path);
for (const entry of children) {
let stat = await IOUtils.stat(entry);
if (stat.type == "directory") {
@@ -1122,6 +1124,10 @@ CrashManager.prototype = Object.freeze({
entries.sort((a, b) => {
return a.date - b.date;
});
} catch (ex) {
// Missing events folders are allowed
console.error(ex);
}
return entries;
})();
@@ -1429,6 +1435,7 @@ CrashStore.prototype = Object.freeze({
let encoder = new TextEncoder();
let data = encoder.encode(JSON.stringify(normalized));
try {
let size = await IOUtils.write(this._storePath, data, {
tmpPath: this._storePath + ".tmp",
compress: true,
@@ -1436,6 +1443,10 @@ CrashStore.prototype = Object.freeze({
if (this._telemetrySizeKey) {
Services.telemetry.getHistogramById(this._telemetrySizeKey).add(size);
}
} catch (ex) {
// This operation might fail during shutdown, tough luck.
console.error(ex);
}
})();
},