Patchwork dispatch: ignore further SIGPIPE while handling KeyboardInterrupt

login
register
mail settings
Submitter Yuya Nishihara
Date April 17, 2017, 3:28 p.m.
Message ID <f2e785be58090ea27130.1492442929@mimosa>
Download mbox | patch
Permalink /patch/20252/
State Accepted
Headers show

Comments

Yuya Nishihara - April 17, 2017, 3:28 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1492440799 -32400
#      Mon Apr 17 23:53:19 2017 +0900
# Node ID f2e785be58090ea271305ade6b744f0f7ee6344f
# Parent  43ae8cb5a71cffe0aed48127e07c757fc642b2c0
dispatch: ignore further SIGPIPE while handling KeyboardInterrupt

I got the following error by running "hg log" and quitting the pager
immediately. Any output here may trigger another SIGPIPE, so only thing
we can do is to swallow the exception and exit with an error status.

  Traceback (most recent call last):
    File "./hg", line 45, in <module>
      mercurial.dispatch.run()
    File "mercurial/dispatch.py", line 83, in run
      status = (dispatch(req) or 0) & 255
    File "mercurial/dispatch.py", line 167, in dispatch
      req.ui.warn(_("interrupted!\n"))
    File "mercurial/ui.py", line 1224, in warn
      self.write_err(*msg, **opts)
    File "mercurial/ui.py", line 790, in write_err
      self._write_err(*msgs, **opts)
    File "mercurial/ui.py", line 798, in _write_err
      self.ferr.write(a)
    File "mercurial/ui.py", line 129, in _catchterm
      raise error.SignalInterrupt
  mercurial.error.SignalInterrupt

Perhaps this wasn't visible before de5c9d0e02ea because the original stderr
handle was restored very late.
Augie Fackler - April 18, 2017, 3:38 p.m.
On Tue, Apr 18, 2017 at 12:28:49AM +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1492440799 -32400
> #      Mon Apr 17 23:53:19 2017 +0900
> # Node ID f2e785be58090ea271305ade6b744f0f7ee6344f
> # Parent  43ae8cb5a71cffe0aed48127e07c757fc642b2c0
> dispatch: ignore further SIGPIPE while handling KeyboardInterrupt

queued, thanks

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -165,6 +165,10 @@  def dispatch(req):
     except KeyboardInterrupt:
         try:
             req.ui.warn(_("interrupted!\n"))
+        except error.SignalInterrupt:
+            # maybe pager would quit without consuming all the output, and
+            # SIGPIPE was raised. we cannot print anything in this case.
+            pass
         except IOError as inst:
             if inst.errno != errno.EPIPE:
                 raise