Mercurial > hg
diff mercurial/keepalive.py @ 39816:1cf1680b0554
keepalive: be more careful about self._rbuf when calling super impls
In Python 3, HTTPResponse implements read() in terms of readinto(),
which was calling back into our readinto(), which duplicates
self._rbuf if it's not empty. Before calling into super's read(),
ensure self._rbuf is empty.
Inheritance is bad, and undocumented self-use of your public API is
one of many reasons.
Differential Revision: https://phab.mercurial-scm.org/D4728
author | Augie Fackler <augie@google.com> |
---|---|
date | Mon, 24 Sep 2018 22:45:32 -0400 |
parents | d6d094259d9c |
children | f2dffa1359c6 |
line wrap: on
line diff
--- a/mercurial/keepalive.py Mon Sep 17 11:50:59 2018 -0700 +++ b/mercurial/keepalive.py Mon Sep 24 22:45:32 2018 -0400 @@ -417,9 +417,12 @@ s = self._rbuf[:amt] self._rbuf = self._rbuf[amt:] return s - - s = self._rbuf + self._raw_read(amt) + # Careful! http.client.HTTPResponse.read() on Python 3 is + # implemented using readinto(), which can duplicate self._rbuf + # if it's not empty. + s = self._rbuf self._rbuf = '' + s += self._raw_read(amt) return s # stolen from Python SVN #68532 to fix issue1088