From 50ee61545aa8ef285ddc8577a4de90d74b32adf5 Mon Sep 17 00:00:00 2001
From: Simon Kornblith <simon@simonster.com>
Date: Wed, 1 Jul 2015 20:34:54 -0400
Subject: [PATCH] Kill code to ensure that our pipe is open before we write to
 the other

In practice, this appears to be both unnecessary and harmful. Although
the first write happens effectively instantaneously, we can take
several hundred milliseconds to read the second write, and Standalone
can decide we are dead.

This apparently fixes #783 for @dstillman, although I was never able to
reproduce locally.
---
 chrome/content/zotero/xpcom/ipc.js | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)

diff --git a/chrome/content/zotero/xpcom/ipc.js b/chrome/content/zotero/xpcom/ipc.js
index bcb10f11f..cc7de5981 100755
--- a/chrome/content/zotero/xpcom/ipc.js
+++ b/chrome/content/zotero/xpcom/ipc.js
@@ -24,7 +24,7 @@
 */
 
 Zotero.IPC = new function() {
-	var _libc, _libcPath, _instancePipe, _user32, open, write, close, instancePipeOpen;
+	var _libc, _libcPath, _instancePipe, _user32, open, write, close;
 	
 	/**
 	 * Initialize pipe for communication with connector
@@ -253,21 +253,12 @@ Zotero.IPC = new function() {
 				}
 				
 				if(!defunct) {
-					// make sure instance pipe is open and accepting input, so that we can receive
-					// a response to whatever we're sending
-					if(!instancePipeOpen && _instancePipe.exists()) {
-						var time = Date.now();
-						Zotero.IPC.safePipeWrite(_instancePipe, "test\n", true);
-						Zotero.debug("IPC: Pipe took "+(Date.now() - time)+" ms to receive a cross-thread write");
-						instancePipeOpen = true;
-					}
-					
-					// Try to write to the pipe once a ms for 1000 ms
-					var timeout = Date.now()+1000, wroteToPipe;
+					// Try to write to the pipe for 100 ms
+					var time = Date.now(), timeout = time+100, wroteToPipe;
 					do {
 						wroteToPipe = Zotero.IPC.safePipeWrite(pipe, msg+"\n");
 					} while(Date.now() < timeout && !wroteToPipe);
-					if (wroteToPipe) Zotero.debug('IPC: Pipe took '+(Date.now()-(timeout-1000))+' ms to become available');
+					if (wroteToPipe) Zotero.debug('IPC: Pipe took '+(Date.now()-time)+' ms to become available');
 					success = success || wroteToPipe;
 					defunct = !wroteToPipe;
 				}