From c90b7cd9b44d02cf8c94ca92bb98266915896841 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 11 Feb 2020 18:32:38 +0000 Subject: [PATCH] git-cache-proxy: Abandon fetch attempt if client disconnects The git client sends the command and then waits for our response. We can tell if it has disconnected, because our stdin (the socket) will be readable. This is a good idea because otherwise if we have clients with their own (formal or informal) timeouts, we can build up a backlog of queued useless fetch attempts. Signed-off-by: Ian Jackson --- scripts/git-cache-proxy | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/git-cache-proxy b/scripts/git-cache-proxy index 518ca9a..636ebfe 100755 --- a/scripts/git-cache-proxy +++ b/scripts/git-cache-proxy @@ -321,6 +321,19 @@ sub clonefetch () { if ($fetch) { + my $rbits = ''; + vec($rbits,0,1) = 1; + my $ebits = $rbits; + my $r=select $rbits,undef,$ebits,0; + $r>=0 or fail "select recheck STDOUT failed: $!"; + if ($r) { + servinfo 'client disconnected (stdin unexpectedly'. + (vec($rbits,0,1) ? ' readable' : ''). + (vec($ebits,0,1) ? ' exception' : ''). + ')'; + exit 0; + } + our @cmd; if (!$exists) { -- 2.30.2