Patchwork D1703: logtoprocess: connect all fds to /dev/null to avoid bad interaction with pager

login
register
mail settings
Submitter phabricator
Date Dec. 15, 2017, 10:15 a.m.
Message ID <differential-rev-PHID-DREV-d7m3gkm5jbzxxizs56ji-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/26301/
State Superseded
Headers show

Comments

phabricator - Dec. 15, 2017, 10:15 a.m.
lothiraldan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  We detected that pager is waiting for log-to-process script to finish, which
  is annoying when adding a script on commandfinish that does an HTTP push.
  
  There seems to be no workaround on the script side and it will make the
  behavior on Linux/MacOS closer to the Windows behavior.
  
  The drawback is that it makes the related tests more flaky as log-to-process
  outputs are now really asynchronous.
  
  If it's considered a BC change, another option would be to add a config option
  for this new behavior. I personally think that the different behavior between
  Windows and Linux is confusing and that it's a bug I would be fine with a new
  config option.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1703

AFFECTED FILES
  hgext/logtoprocess.py
  tests/test-logtoprocess.t

CHANGE DETAILS




To: lothiraldan, #hg-reviewers
Cc: mercurial-devel
phabricator - Dec. 15, 2017, 2:11 p.m.
yuja added inline comments.

INLINE COMMENTS

> logtoprocess.py:94
> +                # and pager will wait for scripts to end if we don't do that
> +                nullrfd = open(os.devnull, 'r')
> +                nullwfd = open(os.devnull, 'w')

Better to close these file objects in the parent process, though that wouldn't matter.

As we only need a file descriptor, `os.open(os.devnull, os.O_RDWR)` can be used.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1703

To: lothiraldan, #hg-reviewers
Cc: yuja, mercurial-devel
phabricator - Oct. 1, 2018, 10:22 a.m.
lothiraldan abandoned this revision.
lothiraldan added a comment.


  Replaced by https://phab.mercurial-scm.org/D4816

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D1703

To: lothiraldan, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-logtoprocess.t b/tests/test-logtoprocess.t
--- a/tests/test-logtoprocess.t
+++ b/tests/test-logtoprocess.t
@@ -122,4 +122,4 @@ 
   $ touch $TESTTMP/wait-for-touched
   $ sleep 0.2
   $ test -f $TESTTMP/touched && echo "SUCCESS Pager is waiting on ltp" || echo "FAIL Pager is waiting on ltp"
-  FAIL Pager is waiting on ltp
+  SUCCESS Pager is waiting on ltp
diff --git a/hgext/logtoprocess.py b/hgext/logtoprocess.py
--- a/hgext/logtoprocess.py
+++ b/hgext/logtoprocess.py
@@ -87,11 +87,16 @@ 
             else:
                 newsession = {'start_new_session': True}
             try:
-                # connect stdin to devnull to make sure the subprocess can't
-                # muck up that stream for mercurial.
+                # connect std* to devnull to make sure the subprocess can't
+                # muck up these stream for mercurial.
+                # Connect all the streams to be more close to Windows behavior
+                # and pager will wait for scripts to end if we don't do that
+                nullrfd = open(os.devnull, 'r')
+                nullwfd = open(os.devnull, 'w')
                 subprocess.Popen(
-                    script, shell=True, stdin=open(os.devnull, 'r'), env=env,
-                    close_fds=True, **newsession)
+                    script, shell=True, stdin=nullrfd,
+                    stdout=nullwfd, stderr=nullwfd,
+                    env=env, close_fds=True, **newsession)
             finally:
                 # mission accomplished, this child needs to exit and not
                 # continue the hg process here.