1
0
Fork 0

Fix abort of downloads and zip extraction to happen immediately, fixes #9390

pull/9702/head
Jordi Boggiano 2021-02-10 17:34:15 +01:00
parent b724adde10
commit f37f3dab04
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 12 additions and 3 deletions

View File

@ -16,6 +16,7 @@ use Composer\Config;
use Composer\Cache;
use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Exception\IrrecoverableDownloadException;
use Composer\Package\Comparer\Comparer;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Operation\InstallOperation;
@ -219,6 +220,10 @@ class FileDownloader implements DownloaderInterface, ChangeReportInterface
}
$self->clearLastCacheWrite($package);
if ($e instanceof IrrecoverableDownloadException) {
throw $e;
}
if ($e instanceof TransportException) {
// if we got an http response with a proper code, then requesting again will probably not help, abort
if ((0 !== $e->getCode() && !in_array($e->getCode(), array(500, 502, 503, 504))) || !$retries) {

View File

@ -19,6 +19,7 @@ use Composer\Util\Http\Response;
use Composer\Composer;
use Composer\Package\Version\VersionParser;
use Composer\Semver\Constraint\Constraint;
use Composer\Exception\IrrecoverableDownloadException;
use React\Promise\Promise;
/**
@ -257,10 +258,11 @@ class HttpDownloader
if (isset($job['curl_id'])) {
$curl->abortRequest($job['curl_id']);
}
throw new IrrecoverableDownloadException('Download of ' . Url::sanitize($job['request']['url']) . ' canceled');
};
$promise = new Promise($resolver, $canceler);
$promise->then(function ($response) use (&$job, $downloader) {
$promise = $promise->then(function ($response) use (&$job, $downloader) {
$job['status'] = HttpDownloader::STATUS_COMPLETED;
$job['response'] = $response;
@ -306,7 +308,7 @@ class HttpDownloader
if (isset($job['request']['options']['http']['header']) && false !== stripos(implode('', $job['request']['options']['http']['header']), 'if-modified-since')) {
$resolve(new Response(array('url' => $url), 304, array(), ''));
} else {
$e = new TransportException('Network disabled, request canceled: '.$url, 499);
$e = new TransportException('Network disabled, request canceled: '.Url::sanitize($url), 499);
$e->setStatusCode(499);
$reject($e);
}
@ -429,7 +431,7 @@ class HttpDownloader
}
}
$io->writeError('<'.$type.'>'.ucfirst($type).' from '.$url.': '.$data[$type].'</'.$type.'>');
$io->writeError('<'.$type.'>'.ucfirst($type).' from '.Url::sanitize($url).': '.$data[$type].'</'.$type.'>');
}
}

View File

@ -177,6 +177,8 @@ class ProcessExecutor
// signal can throw in various conditions, but we don't care if it fails
}
$job['process']->stop(1);
throw new \RuntimeException('Aborted process');
};
$promise = new Promise($resolver, $canceler);