Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 7fb8e16

Browse files
Pete Wyckoffgitster
authored andcommitted
git-remote-testgit: fix race when spawning fast-import
Test "pushing to local repo" in t5800-remote-helpers can hang due to a race condition in git-remote-testgit. Fix it by setting stdin to unbuffered. On the writer side, "git push" invokes push_refs_with_export(), which sends to stdout the command "export\n" and immediately starts up "git fast-export". The latter writes its output stream to the same stdout. On the reader side, remote helper "git-remote-testgit" reads from stdin to get its next command. It uses getc() to read characters from libc up until \n. Libc has buffered a potentially much larger chunk of stdin. When it sees the "export\n" command, it forks "git fast-import" to read the stream. If fast-export finishes before git fast-import starts, the fast-export output can end up in libc's buffer in git-remote-testgit, rather than in git fast-import. The latter hangs indefinitely on a now-empty stdin. Signed-off-by: Pete Wyckoff <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fdec2eb commit 7fb8e16

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

git-remote-testgit.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
_digest = sha.new
2323
import sys
2424
import os
25+
import time
2526
sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
2627

2728
from git_remote_helpers.util import die, debug, warn
@@ -204,6 +205,11 @@ def read_one_line(repo):
204205
"""Reads and processes one command.
205206
"""
206207

208+
sleepy = os.environ.get("GIT_REMOTE_TESTGIT_SLEEPY")
209+
if sleepy:
210+
debug("Sleeping %d sec before readline" % int(sleepy))
211+
time.sleep(int(sleepy))
212+
207213
line = sys.stdin.readline()
208214

209215
cmdline = line
@@ -258,6 +264,7 @@ def main(args):
258264

259265
more = True
260266

267+
sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
261268
while (more):
262269
more = read_one_line(repo)
263270

t/t5800-remote-helpers.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,19 @@ test_expect_success 'pushing to local repo' '
7272
compare_refs localclone HEAD server HEAD
7373
'
7474

75+
# Generally, skip this test. It demonstrates a now-fixed race in
76+
# git-remote-testgit, but is too slow to leave in for general use.
77+
: test_expect_success 'racily pushing to local repo' '
78+
test_when_finished "rm -rf server2 localclone2" &&
79+
cp -a server server2 &&
80+
git clone "testgit::${PWD}/server2" localclone2 &&
81+
(cd localclone2 &&
82+
echo content >>file &&
83+
git commit -a -m three &&
84+
GIT_REMOTE_TESTGIT_SLEEPY=2 git push) &&
85+
compare_refs localclone2 HEAD server2 HEAD
86+
'
87+
7588
test_expect_success 'synch with changes from localclone' '
7689
(cd clone &&
7790
git pull)

0 commit comments

Comments
 (0)