chiark / gitweb /
git-cache-proxy: Abandon fetch attempt if client disconnects
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 11 Feb 2020 18:32:38 +0000 (18:32 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 11 Feb 2020 18:57:35 +0000 (18:57 +0000)
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 <ian.jackson@eu.citrix.com>
scripts/git-cache-proxy

index 518ca9a8fe8c34b816b34e1a0dd3b176e703bbbc..636ebfecb2adb51e0f0296ccd7a334c3e51ea89e 100755 (executable)
@@ -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) {