Patchwork [2,of,2] chgserver: restore pager fds attached within runcommand session

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 19, 2018, 2:40 p.m.
Message ID <5771a1af26926476b3cd.1537368039@mimosa>
Download mbox | patch
Permalink /patch/34836/
State New
Headers show

Comments

Yuya Nishihara - Sept. 19, 2018, 2:40 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1537366267 -32400
#      Wed Sep 19 23:11:07 2018 +0900
# Node ID 5771a1af26926476b3cdec6c17f78dc1521746c0
# Parent  1d28123b25e42dbd7a5937b7244052fb6922dadb
chgserver: restore pager fds attached within runcommand session

While rewriting chg in Rust, I noticed the server leaks the client's pager
fd. This isn't a problem right now since the IPC process terminates earlier
than the pager, but I believe the fds attached within a "runcommand" request
should be released as soon as the session ends.

Patch

diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -456,7 +456,16 @@  class chgcmdserver(commandserver.server)
         os.umask(mask)
 
     def runcommand(self):
-        return super(chgcmdserver, self).runcommand()
+        # pager may be attached within the runcommand session, which should
+        # be detached at the end of the session. otherwise the pager wouldn't
+        # receive EOF.
+        globaloldios = self._oldios
+        self._oldios = []
+        try:
+            return super(chgcmdserver, self).runcommand()
+        finally:
+            self._restoreio()
+            self._oldios = globaloldios
 
     def setenv(self):
         """Clear and update os.environ