Bug 1599024 - Don't crash when reading bad hangentry type r=froydnj
authorDoug Thayer <dothayer@mozilla.com>
Fri, 20 Mar 2020 20:09:11 +0000
changeset 519906 f6bb224e706a8b4064607d23ff7d44b024ab29e0
parent 519905 94b4897b196378f6c1fd73993039ab0afea0ddfc
child 519907 ab46326057d45d913f3c2e0ac47851309911fec2
push id37235
push userccoroiu@mozilla.com
push dateSat, 21 Mar 2020 03:59:46 +0000
treeherdermozilla-central@bbb78f71a5de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1599024
milestone76.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1599024 - Don't crash when reading bad hangentry type r=froydnj Fairly simple. We should fail gracefully and delete the file if it appears to be corrupted. I wanted to see an example of a corrupted permahang file before fixing this (it's scoped to nightly only, and I wanted to make sure there wasn't a bug in how we're writing these.) The example file was just filled with zeroes at the end. This suggests to me our write calls succeeded when we wrote it, but the OS didn't get a chance to flush its buffers to disk (but it did reserve the required space on disk). I'm not familiar enough with the inner workings of filesystems or the underlying drivers to know if this is plausible or if they should have stronger guarantees of atomicity, but it's good enough for me to conclude that the one instance of a bad last_permahang.bin file I've seen is not directly due to a bug in the writing code. Differential Revision: https://phabricator.services.mozilla.com/D67645
toolkit/components/backgroundhangmonitor/HangDetails.cpp
--- a/toolkit/components/backgroundhangmonitor/HangDetails.cpp
+++ b/toolkit/components/backgroundhangmonitor/HangDetails.cpp
@@ -546,17 +546,17 @@ Result<Ok, nsresult> ReadEntry(PRFileDes
       aStack.stack().AppendElement(HangEntryChromeScript());
       break;
     }
     case HangEntry::THangEntrySuppressed: {
       aStack.stack().AppendElement(HangEntrySuppressed());
       break;
     }
     default:
-      MOZ_CRASH("Unsupported HangEntry type?");
+      return Err(NS_ERROR_UNEXPECTED);
   }
   return Ok();
 }
 
 Result<HangDetails, nsresult> ReadHangDetailsFromFile(nsIFile* aFile) {
   AutoFDClose fd;
   nsresult rv = aFile->OpenNSPRFileDesc(PR_RDONLY, 0644, &fd.rwget());
   if (NS_FAILED(rv)) {