From 09c9957cf77106ca6b49127d5df20080922c81a4 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 25 Apr 2011 23:04:10 +0200 Subject: [PATCH] send-pack: avoid deadlock when pack-object dies early Send-pack deadlocks in two ways when pack-object dies early (for example, because there is some repo corruption). The first deadlock happens with the smart push protocol (--stateless-rpc). After the initial rev-exchange, the remote is waiting for the pack data to arrive, and the sideband demuxer at the local side continues trying to stream data from the remote repository until it gets EOF. Meanwhile, send-pack (in function pack_objects()) has noticed that pack-objects did not produce output and died. Back in send_pack(), it now tries to clean up the sideband demuxer using finish_async(). The demuxer, however, waits for the remote end to close down, the remote waits for pack data, and the reason that it still waits is that send-pack forgot to close the outgoing channel. Add the missing close() in pack_objects(). The second deadlock happens in a similar constellation when the sideband demuxer runs in a forked process (rather than in a thread). Again, the remote end waits for pack data to arrive, the sideband demuxer waits for the remote to shut down, and send-pack (in the regular clean-up) waits for the demuxer to terminate. This time, the send-pack parent process closes the writable end of the outgoing channel (in start_command() that spawned pack-objects) so that after the death of the pack-objects process all writable ends should have been closed and the remote repo should see EOF. This does not happen, however, because when the sideband demuxer was forked earlier, it also inherited a writable end; it remains open and keeps the remote repo from seeing EOF. To break this deadlock, close the writable end in the demuxer. Analyzed-by: Jeff King Signed-off-by: Johannes Sixt Signed-off-by: Junio C Hamano --- builtin-send-pack.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/builtin-send-pack.c b/builtin-send-pack.c index 2478e1851a..6516288711 100644 --- a/builtin-send-pack.c +++ b/builtin-send-pack.c @@ -97,6 +97,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext free(buf); close(po.out); po.out = -1; + close(fd); } if (finish_command(&po)) @@ -375,6 +376,9 @@ static void print_helper_status(struct ref *ref) static int sideband_demux(int in, int out, void *data) { int *fd = data; +#ifndef WIN32 + close(fd[1]); +#endif int ret = recv_sideband("send-pack", fd[0], out); close(out); return ret; -- 2.11.4.GIT