Bug 783054 - part 2: delete unparseable ping files; r=taras
authorNathan Froyd <froydnj@mozilla.com>
Thu, 20 Sep 2012 13:02:02 -0400
changeset 108305 624c912580fbc51b3db45a09227d699ea7a248a7
parent 108304 7ddcdc6f0619f8300f318d5c71d063ff8121c8b5
child 108306 08764617f060d869e0fd552363c7823bd2b478ca
push id23552
push userryanvm@gmail.com
push dateFri, 28 Sep 2012 03:05:08 +0000
treeherdermozilla-central@2d96ee8d9dd4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstaras
bugs783054
milestone18.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 783054 - part 2: delete unparseable ping files; r=taras
toolkit/components/telemetry/TelemetryPing.js
--- a/toolkit/components/telemetry/TelemetryPing.js
+++ b/toolkit/components/telemetry/TelemetryPing.js
@@ -714,52 +714,54 @@ TelemetryPing.prototype = {
     if (!ping.checksum) {
       return true;
     }
 
     let checksumNow = this.hashString(ping.payload);
     return ping.checksum == checksumNow;
   },
 
-  addToPendingPings: function addToPendingPings(stream) {
+  addToPendingPings: function addToPendingPings(file, stream) {
     try {
       let string = NetUtil.readInputStreamToString(stream, stream.available(), { charset: "UTF-8" });
       stream.close();
       let ping = JSON.parse(string);
       this._pingLoadsCompleted++;
 
       if (this.verifyPingChecksum(ping)) {
         this._pendingPings.push(ping);
       }
 
       if (this._doLoadSaveNotifications &&
           this._pingLoadsCompleted == this._pingsLoaded) {
         Services.obs.notifyObservers(null, "telemetry-test-load-complete", null);
       }
     } catch (e) {
       // An error reading the file, or an error parsing the contents.
+      stream.close();           // close is idempotent.
+      file.remove(true);
     }
   },
 
   loadHistograms: function loadHistograms(file, sync) {
     this._pingsLoaded++;
     if (sync) {
       let stream = Cc["@mozilla.org/network/file-input-stream;1"]
                    .createInstance(Ci.nsIFileInputStream);
       stream.init(file, -1, -1, 0);
-      this.addToPendingPings(stream);
+      this.addToPendingPings(file, stream);
     } else {
       let channel = NetUtil.newChannel(file);
       channel.contentType = "application/json"
 
       NetUtil.asyncFetch(channel, (function(stream, result) {
         if (!Components.isSuccessCode(result)) {
           return;
         }
-        this.addToPendingPings(stream);
+        this.addToPendingPings(file, stream);
       }).bind(this));
     }
   },
 
   loadSavedPings: function loadSavedPings(sync) {
     let directory = this.ensurePingDirectory();
     let entries = directory.directoryEntries
                            .QueryInterface(Ci.nsIDirectoryEnumerator);