diff options
author | Jeff King <peff@github.com> | 2011-04-06 17:33:33 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-04-06 14:38:47 -0700 |
commit | b9612197798dbfc622c766e83b1fe4c20bffae5c (patch) | |
tree | 60632d2fcac76911b859bfd96c215c14465cef4c /builtin/remote.c | |
parent | Documentation: trivial grammar fix in core.worktree description (diff) | |
download | tgif-b9612197798dbfc622c766e83b1fe4c20bffae5c.tar.xz |
upload-pack: start pack-objects before async rev-list
In a pthread-enabled version of upload-pack, there's a race condition
that can cause a deadlock on the fflush(NULL) we call from run-command.
What happens is this:
1. Upload-pack is informed we are doing a shallow clone.
2. We call start_async() to spawn a thread that will generate rev-list
results to feed to pack-objects. It gets a file descriptor to a
pipe which will eventually hook to pack-objects.
3. The rev-list thread uses fdopen to create a new output stream
around the fd we gave it, called pack_pipe.
4. The thread writes results to pack_pipe. Outside of our control,
libc is doing locking on the stream. We keep writing until the OS
pipe buffer is full, and then we block in write(), still holding
the lock.
5. The main thread now uses start_command to spawn pack-objects.
Before forking, it calls fflush(NULL) to flush every stdio output
buffer. It blocks trying to get the lock on pack_pipe.
And we have a deadlock. The thread will block until somebody starts
reading from the pipe. But nobody will read from the pipe until we
finish flushing to the pipe.
To fix this, we swap the start order: we start the
pack-objects reader first, and then the rev-list writer
after. Thus the problematic fflush(NULL) happens before we
even open the new file descriptor (and even if it didn't,
flushing should no longer block, as the reader at the end of
the pipe is now active).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/remote.c')
0 files changed, 0 insertions, 0 deletions