Patchwork [1,of,4] client: fail gracefully on unexpected prompts (issue5516)

login
register
mail settings
Submitter Gábor Stefanik
Date Aug. 21, 2017, 4:06 p.m.
Message ID <242d719e85ce451e61ab.1503331580@GSTEFANIK.NavnGo.local>
Download mbox | patch
Permalink /patch/23181/
State Accepted
Headers show

Comments

Gábor Stefanik - Aug. 21, 2017, 4:06 p.m.
# HG changeset patch
# User Gábor Stefanik <gabor.stefanik@nng.com>
# Date 1503326357 -7200
#      Mon Aug 21 16:39:17 2017 +0200
# Node ID 242d719e85ce451e61ab262eec443668bb4792ce
# Parent  8e959ad6a25c9fe6ab490e1a4cbd5f7445d9bcb1
client: fail gracefully on unexpected prompts (issue5516)

Right now, if hglib encounters an unexpected prompt, it fails with a rather
opaque "unexpected data on required channel 'L'" error message. Furthermore,
if subsequently another command is called on the same client instance, both
the client and server processes lock up hard (at least on Windows), and the
server process rapidly leaks ~2GB of memory.

Fix this by responding with an empty string to any unexpected prompt. This
will trigger an "abort: response expected" exception from the server, which
is easily handled as a CommandError, and subsequent commands sent from the
same client work as expected.

This doesn't completely resolve bug 5516, as unexpected requests on another
required channel (e.g. I) can still cause a lockup.
However, it does fix the most common case of an unexpected password prompt.

________________________________
 This message, including its attachments, is confidential and the property of NNG Llc. For more information please read NNG's email policy here:
http://www.nng.com/emailpolicy/
By responding to this email you accept the email policy.
Yuya Nishihara - Aug. 23, 2017, 2:27 p.m.
On Mon, 21 Aug 2017 18:06:20 +0200, Gábor Stefanik wrote:
> # HG changeset patch
> # User Gábor Stefanik <gabor.stefanik@nng.com>
> # Date 1503326357 -7200
> #      Mon Aug 21 16:39:17 2017 +0200
> # Node ID 242d719e85ce451e61ab262eec443668bb4792ce
> # Parent  8e959ad6a25c9fe6ab490e1a4cbd5f7445d9bcb1
> client: fail gracefully on unexpected prompts (issue5516)

These look good to me, thanks.

> Fix this by responding with an empty string to any unexpected prompt. This
> will trigger an "abort: response expected" exception from the server, which
> is easily handled as a CommandError, and subsequent commands sent from the
> same client work as expected.

Yes. An empty response indicates EOF.

Patch

diff -r 8e959ad6a25c -r 242d719e85ce hglib/client.py

--- a/hglib/client.py   Mon Apr 03 16:02:08 2017 -0500

+++ b/hglib/client.py   Mon Aug 21 16:39:17 2017 +0200

@@ -235,6 +235,8 @@ 

                 reply = prompt(size, out.getvalue())
                 return reply
             inchannels[b('L')] = func
+        else:

+            inchannels[b('L')] = lambda _: ''

         if input is not None:
             inchannels[b('I')] = input