Mercurial > python-hglib
comparison hglib/client.py @ 188:5609a21fe39a
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.
author | Gábor Stefanik <gabor.stefanik@nng.com> |
---|---|
date | Tue, 12 Sep 2017 13:16:36 -0400 |
parents | 9062a6b935ad |
children | 8054e925d9c7 |
comparison
equal
deleted
inserted
replaced
187:9062a6b935ad | 188:5609a21fe39a |
---|---|
233 if prompt is not None: | 233 if prompt is not None: |
234 def func(size): | 234 def func(size): |
235 reply = prompt(size, out.getvalue()) | 235 reply = prompt(size, out.getvalue()) |
236 return reply | 236 return reply |
237 inchannels[b('L')] = func | 237 inchannels[b('L')] = func |
238 else: | |
239 inchannels[b('L')] = lambda _: '' | |
238 if input is not None: | 240 if input is not None: |
239 inchannels[b('I')] = input | 241 inchannels[b('I')] = input |
240 | 242 |
241 ret = self.runcommand(args, inchannels, outchannels) | 243 ret = self.runcommand(args, inchannels, outchannels) |
242 out, err = out.getvalue(), err.getvalue() | 244 out, err = out.getvalue(), err.getvalue() |