# HG changeset patch # User Mitchell Plamann # Date 1601918596 14400 # Node ID 2c6b054e22d0b66dd098244fc28b5d5c3e3401e6 # Parent edf4fa06df949c63a44da0db69dec4b621884e01 test: add test-transaction-rollback-on-sigpipe.t demonstrating py3 regression When an hg push is interrupted with C-c, the remote [hg serve] command receives SIGPIPE. If a pretxnchangegroup hook fails, the remote hg then tries to rollback the transaction. It begins by printing "transaction abort!\n". This returns EPIPE, but ui.py ignores that error. In python3 (but not python2), this "transaction abort!\n" message stays in a buffer, so future flushes of stderr will try to print the message again, and so those flushes will also hit EPIPE. This test demonstrates such a case where this EPIPE causes the transaction rollback to fail, leaving behind an abandoned transaction. Differential Revision: https://phab.mercurial-scm.org/D9151 diff -r edf4fa06df94 -r 2c6b054e22d0 tests/test-transaction-rollback-on-sigpipe.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-transaction-rollback-on-sigpipe.t Mon Oct 05 13:23:16 2020 -0400 @@ -0,0 +1,67 @@ +Test that, when an hg push is interrupted and the remote side recieves SIGPIPE, +the remote hg is able to successfully roll back the transaction. + + $ hg init -q remote + $ hg clone -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" -q ssh://user@dummy/`pwd`/remote local + + $ check_for_abandoned_transaction() { + > [[ -f $TESTTMP/remote/.hg/store/journal ]] && echo "Abandoned transaction!" + > } + + $ pidfile=`pwd`/pidfile + $ >$pidfile + + $ script() { + > cat >"$1" + > chmod +x "$1" + > } + +On the remote end, run hg, piping stdout and stderr through processes that we +know the PIDs of. We will later kill these to simulate an ssh client +disconnecting. + + $ killable_pipe=`pwd`/killable_pipe.sh + $ script $killable_pipe < #!/bin/bash + > echo \$\$ >> $pidfile + > exec cat + > EOF + + $ remotecmd=`pwd`/remotecmd.sh + $ script $remotecmd < #!/bin/bash + > hg "\$@" 1> >($killable_pipe) 2> >($killable_pipe >&2) + > EOF + +In the pretxnchangegroup hook, kill the PIDs recorded above to simulate ssh +disconnecting. Then exit nonzero, to force a transaction rollback. + + $ hook_script=`pwd`/pretxnchangegroup.sh + $ script $hook_script < #!/bin/bash + > for pid in \$(cat $pidfile) ; do + > kill \$pid + > while kill -0 \$pid 2>/dev/null ; do + > sleep 0.1 + > done + > done + > exit 1 + > EOF + + $ cat >remote/.hg/hgrc < [hooks] + > pretxnchangegroup.break-things=$hook_script + > EOF + + $ cd local + $ echo foo > foo ; hg commit -qAm "commit" + $ hg push -e "\"$PYTHON\" \"$TESTDIR/dummyssh\"" --remotecmd $remotecmd 2>&1 | grep -v $killable_pipe + pushing to ssh://user@dummy/$TESTTMP/remote + searching for changes + remote: adding changesets + remote: adding manifests + remote: adding file changes + abort: stream ended unexpectedly (got 0 bytes, expected 4) + + $ check_for_abandoned_transaction + Abandoned transaction!