diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -354,9 +354,19 @@ def processbundle(repo, unbundler, trans for nbpart, part in iterparts: _processpart(op, part) except Exception as exc: - for nbpart, part in iterparts: - # consume the bundle content - part.seek(0, 2) + # Any exceptions seeking to the end of the bundle at this point are + # almost certainly related to the underlying stream being bad. + # And, chances are that the exception we're handling is related to + # getting in that bad state. So, we swallow the seeking error and + # re-raise the original error. + seekerror = False + try: + for nbpart, part in iterparts: + # consume the bundle content + part.seek(0, 2) + except Exception: + seekerror = True + # Small hack to let caller code distinguish exceptions from bundle2 # processing from processing the old format. This is mostly # needed to handle different return codes to unbundle according to the @@ -370,7 +380,13 @@ def processbundle(repo, unbundler, trans replycaps = op.reply.capabilities exc._replycaps = replycaps exc._bundle2salvagedoutput = salvaged - raise + + # Re-raising from a variable loses the original stack. So only use + # that form if we need to. + if seekerror: + raise exc + else: + raise finally: repo.ui.debug('bundle2-input-bundle: %i parts total\n' % nbpart) diff --git a/tests/test-http-bad-server.t b/tests/test-http-bad-server.t --- a/tests/test-http-bad-server.t +++ b/tests/test-http-bad-server.t @@ -688,7 +688,8 @@ Server stops sending after bundle2 part adding changesets transaction abort! rollback completed - abort: stream ended unexpectedly (got 0 bytes, expected 4) + abort: HTTP request error (incomplete response) + (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] $ killdaemons.py $DAEMON_PIDS @@ -717,7 +718,8 @@ Server stops after bundle2 part payload adding changesets transaction abort! rollback completed - abort: stream ended unexpectedly (got 0 bytes, expected 4) + abort: HTTP request error (incomplete response) + (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] $ killdaemons.py $DAEMON_PIDS @@ -747,7 +749,8 @@ Server stops sending in middle of bundle adding changesets transaction abort! rollback completed - abort: stream ended unexpectedly (got 0 bytes, expected 4) + abort: HTTP request error (incomplete response) + (this may be an intermittent network failure; if the error persists, consider contacting the network or server operator) [255] $ killdaemons.py $DAEMON_PIDS