commit 40e0c6fee63685472aa179a0bccac7eb333cd160
parent 2b68113fd71ea2f5697b44169fb1e38b592c30dc
Author: Simon Kornblith <simon@simonster.com>
Date: Tue, 14 Jun 2011 04:02:27 +0000
Fix race condition under Firefox 4
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/chrome/content/zotero/xpcom/ipc.js b/chrome/content/zotero/xpcom/ipc.js
@@ -320,6 +320,7 @@ Zotero.IPC.Pipe = new function() {
* deletes it
*/
this.writeShutdownMessage = function(file) {
+ Zotero.debug("IPC: Closing pipe "+file.path);
var oStream = Components.classes["@mozilla.org/network/file-output-stream;1"].
getService(Components.interfaces.nsIFileOutputStream);
oStream.init(file, 0x02 | 0x10, 0, 0);
@@ -327,7 +328,6 @@ Zotero.IPC.Pipe = new function() {
oStream.write(cmd, cmd.length);
oStream.close();
file.remove(false);
- Zotero.debug("IPC: Closing pipe "+file.path);
}
}
@@ -405,7 +405,14 @@ Zotero.IPC.Pipe.WorkerThread = function(file, callback) {
worker.postMessage({"path":file.path, "libc":Zotero.IPC.getLibcPath()});
// add shutdown listener
- Zotero.addShutdownListener(Zotero.IPC.Pipe.writeShutdownMessage.bind(null, file));
+ Zotero.addShutdownListener(function() {
+ // wait for pending events to complete (so that we don't try to close the pipe before it
+ // finishes opening)
+ while(Zotero.mainThread.processNextEvent(false)) {};
+
+ // close pipe
+ Zotero.IPC.Pipe.writeShutdownMessage(file)
+ });
}
Zotero.IPC.Pipe.WorkerThread.prototype = {