Patchwork [1,of,2] tinyproxy: explicitly flush logged messages

login
register
mail settings
Submitter Matt Harbison
Date June 19, 2017, 4:58 a.m.
Message ID <8fd2d66049d936d2cc50.1497848309@Envy>
Download mbox | patch
Permalink /patch/21500/
State Accepted
Headers show

Comments

Matt Harbison - June 19, 2017, 4:58 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1497835913 14400
#      Sun Jun 18 21:31:53 2017 -0400
# Node ID 8fd2d66049d936d2cc501ad9a466fb5e67ed8ac2
# Parent  07d5a503124caed05e1300a5208240764882c831
tinyproxy: explicitly flush logged messages

On Windows, output streams are buffered when redirected to a file, and
TerminateProcess() apparently doesn't trigger a flush.  This left
test-http-proxy.t missing part of the last line when it cat'd proxy.log[1].

Flushing stderr is all that is needed (on py27 anyway).  I originally flushed
stdout too, but that added additional output to the log:

     $ cat proxy.log
  +  Accept: $LOCALIP (localhost)\r (esc)
  +  Serving HTTP on 0.0.0.0 port 20810 ...\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
     * - - [*] "GET http://localhost:$HGPORT/?cmd=capabilities HTTP/1.1" - - (glob)
  +       bye\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
     * - - [*] "GET http://localhost:$HGPORT/?cmd=branchmap HTTP/1.1" - - x-hgproto-1:0.1 0.2 comp=*zlib,none,bzip2 (glob)
  +       bye\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
     * - - [*] "GET http://localhost:$HGPORT/?cmd=stream_out HTTP/1.1" - - x-hgproto-1:0.1 0.2 comp=*zlib,none,bzip2 (glob)
  +       bye\r (esc)
  +       connect to localhost:$HGPORT\r (esc)
 ...

[1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-April/096987.html
Yuya Nishihara - June 19, 2017, 2 p.m.
On Mon, 19 Jun 2017 00:58:29 -0400, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1497835913 14400
> #      Sun Jun 18 21:31:53 2017 -0400
> # Node ID 8fd2d66049d936d2cc501ad9a466fb5e67ed8ac2
> # Parent  07d5a503124caed05e1300a5208240764882c831
> tinyproxy: explicitly flush logged messages

Queued, thanks.

> Flushing stderr is all that is needed (on py27 anyway).  I originally flushed
> stdout too, but that added additional output to the log:

Ugh, maybe we should redirect stdout to /dev/null.

Patch

diff --git a/tests/tinyproxy.py b/tests/tinyproxy.py
--- a/tests/tinyproxy.py
+++ b/tests/tinyproxy.py
@@ -53,6 +53,8 @@ 
         self.log_message('"%s" %s %s%s',
                          self.requestline, str(code), str(size),
                          ''.join([' %s:%s' % h for h in sorted(xheaders)]))
+        # Flush for Windows, so output isn't lost on TerminateProcess()
+        sys.stderr.flush()
 
     def _connect_to(self, netloc, soc):
         i = netloc.find(':')