Package: apt-cacher
Version: 1.6.3
Severity: normal
Tags: patch

Symptom is that apt-cacher cron job fails upon transient DNS failure
with the following error:

run-parts: /etc/cron.daily/apt-cacher exited with return code 255

Each time this happens, there are a pair of error lines in
/var/log/apt-cacher/error.log, as follows:

Thu Aug 14 03:53:49 2008|info [30388]: Warning: libcurl failed for 
http://www.mirrorservice.org/sites/ftp.debian.org/debian/dists/../project/experimental/contrib/binary-i386/Release
 with Couldn't resolve host 'www.mirrorservice.org'
Thu Aug 14 03:53:49 2008|error [30388]: Can't use an undefined value as a 
SCALAR reference at /usr/share/apt-cacher/apt-cacher line 1254.

(this error was logged against 1.6.3 but I have checked the code in
1.6.4 and it is the same except for being one line further down).

The problem seems to arise from the following (line numbers relate to
version 1.6.4).

sub libcurl in /usr/share/apt-cacher/apt-cacher can be called with the
third parameter ($pkfdref) set to undef, and in this case sub libcurl
will send a HEAD request rather than a GET (lines 1222 - 1246).

If there is a virtual host map, which I have, then the response
will be checked and considered for retry (line 1248).  In my case
www.mirrorservice.org is not the last hostname in that vhost.  So when the
curl request to that host fails, the 'if ...  is_success || ! @{$pathmap
...}' at line 1250 fails.

Remember that $pkfdref may be 'undef'.  However at lines 1255 and 1256
$pkfdref is now unconditionally used as a scalar reference.

I think that the truncate and sysseek which reference $$pkgdref should
be wrapped in a check for that variable being defined, before doing the
'goto RETRY_ACTION'.  A patch to do this is attached.

Addendum: upon checking further up apt-cacher error.log I have seen the
same error during normal running.  Definitely worth fixing I think as
the error prevents subsequent hostnames in the vhost from being tried.

Nick
--- /usr/share/apt-cacher/apt-cacher.orig	2008-05-27 22:28:41.000000000 +0100
+++ /usr/share/apt-cacher/apt-cacher	2008-08-14 07:26:43.000000000 +0100
@@ -1250,9 +1250,11 @@
 	    unshift(@{$pathmap{$vhost}}, $hostcand);
 	}
 	else {
-	    # truncate cached_file to remove previous HTTP error
-	    truncate($$pkfdref, 0);
-	    sysseek($$pkfdref, 0, 0);
+	    if($pkfdref) {
+		# truncate cached_file to remove previous HTTP error
+		truncate($$pkfdref, 0);
+		sysseek($$pkfdref, 0, 0);
+	    }
 	    goto RETRY_ACTION;
 	}
     }

Reply via email to