Bug 965527 - Harden OS.File shutdown flag. r=froydnj
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Thu, 06 Mar 2014 12:50:28 -0500
changeset 189539 9a5b7ed8dae47207f8871d8330215e4c43bee86f
parent 189538 bac0b83a239494e45e2dfb79cf31ae7d0fedae96
child 189540 0a0fcc54e630f0b7e1050b660cbe0d86126bc542
push id3503
push userraliiev@mozilla.com
push dateMon, 28 Apr 2014 18:51:11 +0000
treeherdermozilla-beta@c95ac01e332e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs965527
milestone30.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 965527 - Harden OS.File shutdown flag. r=froydnj
toolkit/components/osfile/modules/osfile_async_front.jsm
--- a/toolkit/components/osfile/modules/osfile_async_front.jsm
+++ b/toolkit/components/osfile/modules/osfile_async_front.jsm
@@ -195,17 +195,23 @@ let Scheduler = {
    *
    * @param {function} code A function returning a Promise.
    * This function will be executed once all the previously
    * pushed tasks have completed.
    * @return {Promise} A promise with the same behavior as
    * the promise returned by |code|.
    */
   push: function(code) {
-    let promise = this.queue.then(code);
+    let promise = this.queue.then(function() {
+      if (this.shutdown) {
+        LOG("OS.File is not available anymore. Request has been rejected.");
+        throw new Error("OS.File has been shut down.");
+      }
+      return code();
+    }.bind(this));
     // By definition, |this.queue| can never reject.
     this.queue = promise.then(null, () => undefined);
     // Fork |promise| to ensure that uncaught errors are reported
     return promise.then(null, null);
   },
 
   /**
    * Post a message to the worker thread.
@@ -403,24 +409,23 @@ const PREF_OSFILE_TEST_SHUTDOWN_OBSERVER
  * @return {promise} A promise satisfied once all pending messages
  * (including the shutdown warning message) have been answered.
  */
 function warnAboutUnclosedFiles(shutdown = true) {
   if (!Scheduler.launched || !worker) {
     // Don't launch the scheduler on our behalf. If no message has been
     // sent to the worker, we can't have any leaking file/directory
     // descriptor.
+    Scheduler.shutdown = Scheduler.shutdown || shutdown;
     return null;
   }
   let promise = Scheduler.post("Meta_getUnclosedResources");
 
   // Configure the worker to reject any further message.
-  if (shutdown) {
-    Scheduler.shutdown = true;
-  }
+  Scheduler.shutdown = Scheduler.shutdown || shutdown;
 
   return promise.then(function onSuccess(opened) {
     let msg = "";
     if (opened.openedFiles.length > 0) {
       msg += "The following files are still open:\n" +
         opened.openedFiles.join("\n");
     }
     if (msg) {