summaryrefslogtreecommitdiff
path: root/git-remote-testgit.py
diff options
context:
space:
mode:
authorPete Wyckoff <pw@padd.com>2012-04-22 20:30:58 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-04-24 21:54:24 (GMT)
commit7fb8e163bdfdc5ffb69b98f3f05ef0dbade4e677 (patch)
treefd59cfc42d64520337820b4485c744096db4d4fd /git-remote-testgit.py
parentfdec2eb8ebbf995a77e2ab9971565c792b52944a (diff)
downloadgit-7fb8e163bdfdc5ffb69b98f3f05ef0dbade4e677.zip
git-7fb8e163bdfdc5ffb69b98f3f05ef0dbade4e677.tar.gz
git-7fb8e163bdfdc5ffb69b98f3f05ef0dbade4e677.tar.bz2
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 <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-remote-testgit.py')
-rw-r--r--git-remote-testgit.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/git-remote-testgit.py b/git-remote-testgit.py
index 3dc4851..5f3ebd2 100644
--- a/git-remote-testgit.py
+++ b/git-remote-testgit.py
@@ -22,6 +22,7 @@ except ImportError:
_digest = sha.new
import sys
import os
+import time
sys.path.insert(0, os.getenv("GITPYTHONLIB","."))
from git_remote_helpers.util import die, debug, warn
@@ -204,6 +205,11 @@ def read_one_line(repo):
"""Reads and processes one command.
"""
+ sleepy = os.environ.get("GIT_REMOTE_TESTGIT_SLEEPY")
+ if sleepy:
+ debug("Sleeping %d sec before readline" % int(sleepy))
+ time.sleep(int(sleepy))
+
line = sys.stdin.readline()
cmdline = line
@@ -258,6 +264,7 @@ def main(args):
more = True
+ sys.stdin = os.fdopen(sys.stdin.fileno(), 'r', 0)
while (more):
more = read_one_line(repo)