diff --git a/mercurial/exchange.py b/mercurial/exchange.py
index aff2aca3420e6d238b537378deb94350d8a707ac_bWVyY3VyaWFsL2V4Y2hhbmdlLnB5..6b81309d15a76b94b941c46f7309b27d59bced48_bWVyY3VyaWFsL2V4Y2hhbmdlLnB5 100644
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1298,8 +1298,12 @@
                 tr.hookargs['url'] = url
                 tr.hookargs['bundle2'] = '1'
                 r = bundle2.processbundle(repo, cg, lambda: tr).reply
+                if r is not None:
+                    repo.ui.pushbuffer(error=True, subproc=True)
+                    def recordout(output):
+                        r.newpart('output', data=output, mandatory=False)
                 tr.close()
             except Exception, exc:
                 exc.duringunbundle2 = True
                 if r is not None:
                     parts = exc._bundle2salvagedoutput = r.salvageoutput()
@@ -1301,9 +1305,8 @@
                 tr.close()
             except Exception, exc:
                 exc.duringunbundle2 = True
                 if r is not None:
                     parts = exc._bundle2salvagedoutput = r.salvageoutput()
-                    repo.ui.pushbuffer(error=True, subproc=True)
                     def recordout(output):
                         part = bundle2.bundlepart('output', data=output,
                                                   mandatory=False)
diff --git a/tests/test-bundle2-exchange.t b/tests/test-bundle2-exchange.t
index aff2aca3420e6d238b537378deb94350d8a707ac_dGVzdHMvdGVzdC1idW5kbGUyLWV4Y2hhbmdlLnQ=..6b81309d15a76b94b941c46f7309b27d59bced48_dGVzdHMvdGVzdC1idW5kbGUyLWV4Y2hhbmdlLnQ= 100644
--- a/tests/test-bundle2-exchange.t
+++ b/tests/test-bundle2-exchange.t
@@ -212,17 +212,8 @@
   $ hg -R main push other --rev eea13746799a --bookmark book_eea1
   pushing to other
   searching for changes
-  pre-close-tip:eea13746799a public book_eea1
-  pushkey: lock state after "phases"
-  lock:  free
-  wlock: free
-  pushkey: lock state after "bookmarks"
-  lock:  free
-  wlock: free
-  postclose-tip:eea13746799a public book_eea1
-  txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_NEW_OBSMARKERS=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_PHASES_MOVED=1 HG_SOURCE=push HG_TXNID=TXN:* HG_TXNNAME=push HG_URL=push (glob)
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 0 changes to 0 files (-1 heads)
   remote: 1 new obsolescence markers
@@ -224,8 +215,17 @@
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 0 changes to 0 files (-1 heads)
   remote: 1 new obsolescence markers
+  remote: pre-close-tip:eea13746799a public book_eea1
+  remote: pushkey: lock state after "phases"
+  remote: lock:  free
+  remote: wlock: free
+  remote: pushkey: lock state after "bookmarks"
+  remote: lock:  free
+  remote: wlock: free
+  remote: postclose-tip:eea13746799a public book_eea1
+  remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_NEW_OBSMARKERS=1 HG_NODE=eea13746799a9e0bfd88f29d3c2e9dc9389f524f HG_PHASES_MOVED=1 HG_SOURCE=push HG_TXNID=TXN:* HG_TXNNAME=push HG_URL=push (glob)
   updating bookmark book_eea1
   pre-close-tip:02de42196ebe draft book_02de
   postclose-tip:02de42196ebe draft book_02de
@@ -304,10 +304,9 @@
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
-  updating bookmark book_5fdd
   remote: pre-close-tip:5fddd98957c8 draft book_5fdd
   remote: pushkey: lock state after "bookmarks"
   remote: lock:  free
   remote: wlock: free
   remote: postclose-tip:5fddd98957c8 draft book_5fdd
   remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_NEW_OBSMARKERS=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_TXNID=TXN:* HG_TXNNAME=serve HG_URL=remote:ssh:127.0.0.1 (glob)
@@ -308,9 +307,10 @@
   remote: pre-close-tip:5fddd98957c8 draft book_5fdd
   remote: pushkey: lock state after "bookmarks"
   remote: lock:  free
   remote: wlock: free
   remote: postclose-tip:5fddd98957c8 draft book_5fdd
   remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_NEW_OBSMARKERS=1 HG_NODE=5fddd98957c8a54a4d436dfe1da9d87f21a1b97b HG_SOURCE=serve HG_TXNID=TXN:* HG_TXNNAME=serve HG_URL=remote:ssh:127.0.0.1 (glob)
+  updating bookmark book_5fdd
   pre-close-tip:02de42196ebe draft book_02de
   postclose-tip:02de42196ebe draft book_02de
   txnclose hook: HG_SOURCE=push-response HG_TXNID=TXN:* HG_TXNNAME=push-response (glob)
@@ -355,6 +355,15 @@
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: 1 new obsolescence markers
+  remote: pre-close-tip:32af7686d403 public book_32af
+  remote: pushkey: lock state after "phases"
+  remote: lock:  free
+  remote: wlock: free
+  remote: pushkey: lock state after "bookmarks"
+  remote: lock:  free
+  remote: wlock: free
+  remote: postclose-tip:32af7686d403 public book_32af
+  remote: txnclose hook: HG_BOOKMARK_MOVED=1 HG_BUNDLE2=1 HG_NEW_OBSMARKERS=1 HG_NODE=32af7686d403cf45b5d95f2d70cebea587ac806a HG_PHASES_MOVED=1 HG_SOURCE=serve HG_TXNID=TXN:* HG_TXNNAME=serve HG_URL=remote:http:127.0.0.1: (glob)
   updating bookmark book_32af
   pre-close-tip:02de42196ebe draft book_02de
   postclose-tip:02de42196ebe draft book_02de
@@ -548,7 +557,7 @@
   > [failpush]
   > reason =
   > [hooks]
-  > pretxnclose.failpush = false
+  > pretxnclose.failpush = echo "You shall not pass!"; false
   > txnabort.failpush = echo 'Cleaning up the mess...'
   > EOF
 
@@ -559,8 +568,7 @@
   $ hg -R main push other -r e7ec4e813ba6
   pushing to other
   searching for changes
-  pre-close-tip:e7ec4e813ba6 draft 
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
@@ -563,7 +571,9 @@
   remote: adding changesets
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
+  remote: pre-close-tip:e7ec4e813ba6 draft 
+  remote: You shall not pass!
   remote: transaction abort!
   remote: Cleaning up the mess...
   remote: rollback completed
@@ -577,7 +587,9 @@
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
+  remote: pre-close-tip:e7ec4e813ba6 draft 
+  remote: You shall not pass!
   remote: transaction abort!
   remote: Cleaning up the mess...
   remote: rollback completed
   abort: pretxnclose.failpush hook exited with status 1
@@ -580,8 +592,7 @@
   remote: transaction abort!
   remote: Cleaning up the mess...
   remote: rollback completed
   abort: pretxnclose.failpush hook exited with status 1
-  remote: pre-close-tip:e7ec4e813ba6 draft 
   [255]
 
   $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
@@ -591,6 +602,8 @@
   remote: adding manifests
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
+  remote: pre-close-tip:e7ec4e813ba6 draft 
+  remote: You shall not pass!
   remote: transaction abort!
   remote: Cleaning up the mess...
   remote: rollback completed