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 <peff@peff.net> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
38a81b4e82
commit
09c9957cf7
@ -97,6 +97,7 @@ static int pack_objects(int fd, struct ref *refs, struct extra_have_objects *ext
|
|||||||
free(buf);
|
free(buf);
|
||||||
close(po.out);
|
close(po.out);
|
||||||
po.out = -1;
|
po.out = -1;
|
||||||
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finish_command(&po))
|
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)
|
static int sideband_demux(int in, int out, void *data)
|
||||||
{
|
{
|
||||||
int *fd = data;
|
int *fd = data;
|
||||||
|
#ifndef WIN32
|
||||||
|
close(fd[1]);
|
||||||
|
#endif
|
||||||
int ret = recv_sideband("send-pack", fd[0], out);
|
int ret = recv_sideband("send-pack", fd[0], out);
|
||||||
close(out);
|
close(out);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user