@@ -1178,6 +1178,14 @@ protected function fetchFile($filename, $cacheKey = null, $sha256 = null, $store
11781178 throw $ e ;
11791179 }
11801180
1181+ // try to detect offline state (if dns resolution fails it is pretty likely to keep failing) and avoid retrying in that case
1182+ if ($ e instanceof TransportException && $ e ->getStatusCode () === null ) {
1183+ $ responseInfo = $ e ->getResponseInfo ();
1184+ if (isset ($ responseInfo ['namelookup_time ' ]) && $ responseInfo ['namelookup_time ' ] == 0 ) {
1185+ $ retries = 0 ;
1186+ }
1187+ }
1188+
11811189 if ($ retries ) {
11821190 usleep (100000 );
11831191 continue ;
@@ -1349,7 +1357,7 @@ private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null)
13491357 return $ data ;
13501358 };
13511359
1352- $ reject = function ($ e ) use (&$ retries , $ httpDownloader , $ filename , $ options , &$ reject , $ accept , $ io , $ url , &$ degradedMode , $ repo ) {
1360+ $ reject = function ($ e ) use (&$ retries , $ httpDownloader , $ filename , $ options , &$ reject , $ accept , $ io , $ url , &$ degradedMode , $ repo, $ lastModifiedTime ) {
13531361 if ($ e instanceof TransportException && $ e ->getStatusCode () === 404 ) {
13541362 $ repo ->packagesNotFoundCache [$ filename ] = true ;
13551363
@@ -1361,6 +1369,14 @@ private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null)
13611369 $ retries = 0 ;
13621370 }
13631371
1372+ // try to detect offline state (if dns resolution fails it is pretty likely to keep failing) and avoid retrying in that case
1373+ if ($ e instanceof TransportException && $ e ->getStatusCode () === null ) {
1374+ $ responseInfo = $ e ->getResponseInfo ();
1375+ if (isset ($ responseInfo ['namelookup_time ' ]) && $ responseInfo ['namelookup_time ' ] == 0 ) {
1376+ $ retries = 0 ;
1377+ }
1378+ }
1379+
13641380 if (--$ retries > 0 ) {
13651381 usleep (100000 );
13661382
@@ -1372,6 +1388,11 @@ private function asyncFetchFile($filename, $cacheKey, $lastModifiedTime = null)
13721388 }
13731389 $ degradedMode = true ;
13741390
1391+ // if the file is in the cache, we fake a 304 Not Modified to allow the process to continue
1392+ if ($ lastModifiedTime ) {
1393+ return $ accept (new Response (array ('url ' => $ url ), 304 , array (), '' ));
1394+ }
1395+
13751396 // special error code returned when network is being artificially disabled
13761397 if ($ e instanceof TransportException && $ e ->getStatusCode () === 499 ) {
13771398 return $ accept (new Response (array ('url ' => $ url ), 404 , array (), '' ));
0 commit comments