1
0
Fork 0

Fix ComposerRepository handling of offline state to allow resolution as long as everything is present in the cache, fixes #10116

pull/10150/head
Jordi Boggiano 2021-10-02 21:22:10 +02:00
parent edccad4e05
commit a7963b7fed
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 23 additions and 1 deletions

View File

@ -1178,6 +1178,14 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
throw $e; throw $e;
} }
// try to detect offline state (if dns resolution fails it is pretty likely to keep failing) and avoid retrying in that case
if ($e instanceof TransportException && $e->getStatusCode() === null) {
$responseInfo = $e->getResponseInfo();
if (isset($responseInfo['namelookup_time']) && $responseInfo['namelookup_time'] == 0) {
$retries = 0;
}
}
if ($retries) { if ($retries) {
usleep(100000); usleep(100000);
continue; continue;
@ -1349,7 +1357,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return $data; return $data;
}; };
$reject = function ($e) use (&$retries, $httpDownloader, $filename, $options, &$reject, $accept, $io, $url, &$degradedMode, $repo) { $reject = function ($e) use (&$retries, $httpDownloader, $filename, $options, &$reject, $accept, $io, $url, &$degradedMode, $repo, $lastModifiedTime) {
if ($e instanceof TransportException && $e->getStatusCode() === 404) { if ($e instanceof TransportException && $e->getStatusCode() === 404) {
$repo->packagesNotFoundCache[$filename] = true; $repo->packagesNotFoundCache[$filename] = true;
@ -1361,6 +1369,14 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
$retries = 0; $retries = 0;
} }
// try to detect offline state (if dns resolution fails it is pretty likely to keep failing) and avoid retrying in that case
if ($e instanceof TransportException && $e->getStatusCode() === null) {
$responseInfo = $e->getResponseInfo();
if (isset($responseInfo['namelookup_time']) && $responseInfo['namelookup_time'] == 0) {
$retries = 0;
}
}
if (--$retries > 0) { if (--$retries > 0) {
usleep(100000); usleep(100000);
@ -1372,6 +1388,11 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
} }
$degradedMode = true; $degradedMode = true;
// if the file is in the cache, we fake a 304 Not Modified to allow the process to continue
if ($lastModifiedTime) {
return $accept(new Response(array('url' => $url), 304, array(), ''));
}
// special error code returned when network is being artificially disabled // special error code returned when network is being artificially disabled
if ($e instanceof TransportException && $e->getStatusCode() === 499) { if ($e instanceof TransportException && $e->getStatusCode() === 499) {
return $accept(new Response(array('url' => $url), 404, array(), '')); return $accept(new Response(array('url' => $url), 404, array(), ''));

View File

@ -341,6 +341,7 @@ class CurlDownloader
if (!$error && function_exists('curl_strerror')) { if (!$error && function_exists('curl_strerror')) {
$error = curl_strerror($errno); $error = curl_strerror($errno);
} }
$progress['error_code'] = $errno;
throw new TransportException('curl error '.$errno.' while downloading '.Url::sanitize($progress['url']).': '.$error); throw new TransportException('curl error '.$errno.' while downloading '.Url::sanitize($progress['url']).': '.$error);
} }
$statusCode = $progress['http_code']; $statusCode = $progress['http_code'];