Skip to content

Commit 4dd75a1

Browse files
committed
Merge branch 'jk/fetch-pack-v2-half-close-early'
"git fetch" over protocol v2 left its side of the socket open after it finished speaking, which unnecessarily wasted the resource on the other side. * jk/fetch-pack-v2-half-close-early: fetch-pack: signal v2 server that we are done making requests
2 parents 0dd2fd1 + ae1a7ee commit 4dd75a1

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

fetch-pack.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,15 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
16451645
if (process_section_header(&reader, "packfile-uris", 1))
16461646
receive_packfile_uris(&reader, &packfile_uris);
16471647
process_section_header(&reader, "packfile", 0);
1648+
1649+
/*
1650+
* this is the final request we'll make of the server;
1651+
* do a half-duplex shutdown to indicate that they can
1652+
* hang up as soon as the pack is sent.
1653+
*/
1654+
close(fd[1]);
1655+
fd[1] = -1;
1656+
16481657
if (get_pack(args, fd, pack_lockfiles,
16491658
packfile_uris.nr ? &index_pack_args : NULL,
16501659
sought, nr_sought, &fsck_options.gitmodules_found))

transport.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ static int fetch_refs_via_pack(struct transport *transport,
427427

428428
cleanup:
429429
close(data->fd[0]);
430-
close(data->fd[1]);
430+
if (data->fd[1] >= 0)
431+
close(data->fd[1]);
431432
if (finish_connect(data->conn))
432433
ret = -1;
433434
data->conn = NULL;
@@ -869,7 +870,8 @@ static int disconnect_git(struct transport *transport)
869870
if (data->got_remote_heads && !transport->stateless_rpc)
870871
packet_flush(data->fd[1]);
871872
close(data->fd[0]);
872-
close(data->fd[1]);
873+
if (data->fd[1] >= 0)
874+
close(data->fd[1]);
873875
finish_connect(data->conn);
874876
}
875877

0 commit comments

Comments
 (0)