[PATCH 2/2] emacs: Fix "no such file or directory" error
authorAustin Clements <amdragon@MIT.EDU>
Sun, 9 Jun 2013 04:45:38 +0000 (00:45 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:55:28 +0000 (09:55 -0800)
47/7b60a6e989d6a1c87be8986c53c38064d96f91 [new file with mode: 0644]

diff --git a/47/7b60a6e989d6a1c87be8986c53c38064d96f91 b/47/7b60a6e989d6a1c87be8986c53c38064d96f91
new file mode 100644 (file)
index 0000000..102380a
--- /dev/null
@@ -0,0 +1,141 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 0BEFC431FC3\r
+       for <notmuch@notmuchmail.org>; Sat,  8 Jun 2013 21:46:13 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id 6IXH3G8+abBO for <notmuch@notmuchmail.org>;\r
+       Sat,  8 Jun 2013 21:46:07 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id B83A0431FB6\r
+       for <notmuch@notmuchmail.org>; Sat,  8 Jun 2013 21:46:01 -0700 (PDT)\r
+X-AuditID: 12074423-b7f546d0000040c3-59-51b408899ae5\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id F7.EE.16579.98804B15; Sun,  9 Jun 2013 00:46:01 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id r594joEU004331; \r
+       Sun, 9 Jun 2013 00:45:50 -0400\r
+Received: from drake.dyndns.org\r
+       (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id r594jmcS009514\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Sun, 9 Jun 2013 00:45:50 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1UlXVk-0003wW-Ie; Sun, 09 Jun 2013 00:45:48 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] emacs: Fix "no such file or directory" error\r
+Date: Sun,  9 Jun 2013 00:45:38 -0400\r
+Message-Id: <1370753138-15021-3-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10.4\r
+In-Reply-To: <1370753138-15021-1-git-send-email-amdragon@mit.edu>\r
+References: <1370753138-15021-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsUixCmqrdvJsSXQ4NVGcYs9+7wsrt+cyezA\r
+       5HH3NJfHs1W3mAOYorhsUlJzMstSi/TtErgy3nRNZCpYJFaxcfo8pgbGyUJdjJwcEgImEl2L\r
+       GtkhbDGJC/fWs3UxcnEICexjlPi3ZzsrSEJIYAOjxM/nWhD2bSaJk3esIIrmMkrMPPcTrJtN\r
+       QENi2/7ljCC2iIC0xM67s4GaOTiYBZwk2tq8QMLCAo4SC2edBAuzCKhK9HytAQnzCjhIXDv4\r
+       E+oGRYnuZxPYQGxOoPK270+YQcqFgGr6u9wnMPIvYGRYxSibklulm5uYmVOcmqxbnJyYl5da\r
+       pGuml5tZopeaUrqJERQ+7C7KOxj/HFQ6xCjAwajEwyuwbnOgEGtiWXFl7iFGSQ4mJVHeFQxb\r
+       AoX4kvJTKjMSizPii0pzUosPMUpwMCuJ8F46D1TOm5JYWZValA+TkuZgURLnvZZy019IID2x\r
+       JDU7NbUgtQgmK8PBoSTB28gONFSwKDU9tSItM6cEIc3EwQkynAdo+GSQGt7igsTc4sx0iPwp\r
+       Rl2Ozecnv2MUYsnLz0uVEuctAikSACnKKM2DmwOL+1eM4kBvCUOM4gGmDLhJr4CWMAEtmf5q\r
+       A8iSkkSElFQD41ljaZOrjRy1xhc/f6jiv9Z9zWxaP+O9m+8nXHpl1tJydG+45SNH0cNXnqYU\r
+       Hdrqu+9FWKjvsR/36r/EJMvLBp8IujpFKX/5gsAPqTKBO1vnBcved2aarvL54k+vRc7P8zZX\r
+       K3yc8eLimm/+LRtFHwtppvAsf5BR9G7Jj+SFFySuHtmn4thbukqJpTgj0VCLuag4EQCjJdc+\r
+       1gIAAA==\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 09 Jun 2013 04:46:13 -0000\r
+\r
+Occasionally, when the user killed the search buffer when the CLI\r
+process was still running, Emacs would run the\r
+notmuch-start-notmuch-sentinel sentinel twice.  The first call would\r
+process and delete the error output file and the second would fail\r
+with an "Opening input file: no such file or directory, ..." error\r
+when attempting to access the error file.\r
+\r
+Emacs isn't supposed to run the sentinel twice.  The reason it does is\r
+rather subtle (and probably a bug in Emacs):\r
+\r
+1) When the user kills the search buffer, Emacs invokes\r
+kill_buffer_processes, which sends a SIGHUP to notmuch, but doesn't do\r
+anything else.  Meanwhile, suppose the notmuch search process has\r
+printed some more output, but Emacs hasn't consumed it yet (this is\r
+critical and is why this error only happens sometimes).\r
+\r
+2) Emacs gets a SIGCHLD from the dying notmuch process, which invokes\r
+handle_child_signal, which sets the new process status, but can't do\r
+anything else because it's a signal handler.\r
+\r
+3) Emacs returns to its idle loop, which calls status_notify, which\r
+sees that the notmuch process has a new status.  This is where things\r
+get interesting.\r
+\r
+3.1) Emacs guarantees that it will run process filters on any\r
+unconsumed output before running the process sentinel, so\r
+status_notify calls read_process_output, which consumes the final\r
+output and calls notmuch-search-process-filter.\r
+\r
+3.1.1) notmuch-search-process-filter checks if the search buffer is\r
+still alive and, since it's not, it calls delete-process.\r
+\r
+3.1.1.1) delete-process correctly sees that the process is already\r
+dead and doesn't try to send another signal, *but* it still modifies\r
+the status to "killed".  To deal with the new status, it calls\r
+status_notify.  Dun dun dun.  We've seen this function before.\r
+\r
+3.1.1.1.1) The *recursive* status_notify invocation sees that the\r
+process has a new status and doesn't have any more output to consume,\r
+so it invokes our sentinel and returns.\r
+\r
+3.2) The outer status_notify call (which we're still in) is now done\r
+flushing pending process output, so it *also* invokes our sentinel.\r
+\r
+This patch addresses this problem at step 3.1.1, where the filter\r
+calls delete-process, since this is a strange and redundant thing to\r
+do anyway.\r
+---\r
+ emacs/notmuch.el |    3 +--\r
+ 1 file changed, 1 insertion(+), 2 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 7994d74..a9949a1 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -821,8 +821,7 @@ non-authors is found, assume that all of the authors match."\r
+       (parse-buf (process-get proc 'parse-buf))\r
+       (inhibit-read-only t)\r
+       done)\r
+-    (if (not (buffer-live-p results-buf))\r
+-      (delete-process proc)\r
++    (when (buffer-live-p results-buf)\r
+       (with-current-buffer parse-buf\r
+       ;; Insert new data\r
+       (save-excursion\r
+-- \r
+1.7.10.4\r
+\r