Skip to content

Commit 4d8cab9

Browse files
peffgitster
authored andcommitted
transport: don't flush when disconnecting stateless-rpc helper
Since ba22785 (Reduce the number of connects when fetching, 2008-02-04), when we disconnect a git transport, we send a final flush packet. This cleanly tells the other side that we're done, and avoids the other side complaining "the remote end hung up unexpectedly" (though we'd only see that for transports that pass along the server stderr, like ssh or local-host). But when we've initiated a v2 stateless-connect session over a transport helper, there's no point in sending this flush packet. Each operation we've performed is self-contained, and the other side is fine with us hanging up between operations. But much worse, by sending the flush packet we may cause the helper to issue an entirely new request _just_ to send the flush packet. So we can incur an extra network request just to say "by the way, we have nothing more to send". Let's drop this extra flush packet. As the test shows, this reduces the number of POSTs required for a v2 ls-remote over http from 2 to 1. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a7312d1 commit 4d8cab9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

t/t5702-protocol-v2.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,18 @@ test_expect_success 'fetch from namespaced repo respects namespaces' '
652652
test_cmp expect actual
653653
'
654654

655+
test_expect_success 'ls-remote with v2 http sends only one POST' '
656+
test_when_finished "rm -f log" &&
657+
658+
git ls-remote "$HTTPD_DOCUMENT_ROOT_PATH/http_parent" >expect &&
659+
GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \
660+
ls-remote "$HTTPD_URL/smart/http_parent" >actual &&
661+
test_cmp expect actual &&
662+
663+
grep "Send header: POST" log >posts &&
664+
test_line_count = 1 posts
665+
'
666+
655667
test_expect_success 'push with http:// and a config of v2 does not request v2' '
656668
test_when_finished "rm -f log" &&
657669
# Till v2 for push is designed, make sure that if a client has

transport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ static int disconnect_git(struct transport *transport)
730730
{
731731
struct git_transport_data *data = transport->data;
732732
if (data->conn) {
733-
if (data->got_remote_heads)
733+
if (data->got_remote_heads && !transport->stateless_rpc)
734734
packet_flush(data->fd[1]);
735735
close(data->fd[0]);
736736
close(data->fd[1]);

0 commit comments

Comments
 (0)