1
0
Fork 0

Make sure Loop abortJobs does not lose track of promises in case wait() is called within the scope of a wait(), refs #9463

pull/9471/head
Jordi Boggiano 2020-11-12 15:14:32 +01:00
parent b0d308319e
commit 4b4a3937ea
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
1 changed files with 11 additions and 6 deletions

View File

@ -25,8 +25,10 @@ class Loop
private $httpDownloader;
/** @var ProcessExecutor|null */
private $processExecutor;
/** @var Promise[]|null */
private $currentPromises;
/** @var Promise[][] */
private $currentPromises = array();
/** @var int */
private $waitIndex = 0;
public function __construct(HttpDownloader $httpDownloader, ProcessExecutor $processExecutor = null)
{
@ -67,7 +69,10 @@ class Loop
}
);
$this->currentPromises = $promises;
// keep track of every group of promises that is waited on, so abortJobs can
// cancel them all, even if wait() was called within a wait()
$waitIndex = $this->waitIndex++;
$this->currentPromises[$waitIndex] = $promises;
if ($progress) {
$totalJobs = 0;
@ -101,7 +106,7 @@ class Loop
usleep(5000);
}
$this->currentPromises = null;
unset($this->currentPromises[$waitIndex]);
if ($uncaught) {
throw $uncaught;
}
@ -109,8 +114,8 @@ class Loop
public function abortJobs()
{
if ($this->currentPromises) {
foreach ($this->currentPromises as $promise) {
foreach ($this->currentPromises as $promiseGroup) {
foreach ($promiseGroup as $promise) {
$promise->cancel();
}
}