From 62c2f7247067c4ab758e911e660963f2e5996518 Mon Sep 17 00:00:00 2001 From: lucashedding <lucashedding@1463982.no-reply.drupal.org> Date: Mon, 25 Nov 2019 14:15:52 -0600 Subject: [PATCH] Issue #3095416 by heddn: HTTP error 429 not handled appropriately --- automatic_updates.module | 4 ++-- src/Services/InPlaceUpdate.php | 7 +++++-- src/Services/Notify.php | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/automatic_updates.module b/automatic_updates.module index f37a9d2c6a..2b020f3af5 100644 --- a/automatic_updates.module +++ b/automatic_updates.module @@ -74,7 +74,7 @@ function automatic_updates_page_top(array &$page_top) { function automatic_updates_cron() { $state = \Drupal::state(); $request_time = \Drupal::time()->getRequestTime(); - $last_check = $state->get('automatic_updates.last_check', 0); + $last_check = $state->get('automatic_updates.cron_last_check', 0); // Only allow cron to run once every hour. if (($request_time - $last_check) < 3600) { return; @@ -115,7 +115,7 @@ function automatic_updates_cron() { foreach ($checker->getCategories() as $category) { $checker->run($category); } - $state->set('automatic_updates.last_check', \Drupal::time()->getCurrentTime()); + $state->set('automatic_updates.cron_last_check', \Drupal::time()->getCurrentTime()); } /** diff --git a/src/Services/InPlaceUpdate.php b/src/Services/InPlaceUpdate.php index 1194a24d64..fdd6f6fbb9 100644 --- a/src/Services/InPlaceUpdate.php +++ b/src/Services/InPlaceUpdate.php @@ -252,12 +252,15 @@ class InPlaceUpdate implements UpdateInterface { $this->httpClient->get($url, [ 'sink' => $destination, 'delay' => $delay, + // Some of the core quasi-patch zip files are large, increase timeout. + 'timeout' => 120, ]); } catch (RequestException $exception) { $response = $exception->getResponse(); - if (!$response || ($retry = $response->getHeader('Retry-After'))) { - $this->doGetResource($url, $destination, !empty($retry[0]) ? $retry[0] : 10 * 1000); + if ($response && $response->getStatusCode() === 429) { + $delay = 1000 * (isset($response->getHeader('Retry-After')[0]) ? $response->getHeader('Retry-After')[0] : 10); + $this->doGetResource($url, $destination, $delay); } else { $this->logger->error('Retrieval of "@url" failed with: @message', [ diff --git a/src/Services/Notify.php b/src/Services/Notify.php index 41b84a50b3..f5dcbe553d 100644 --- a/src/Services/Notify.php +++ b/src/Services/Notify.php @@ -120,9 +120,9 @@ class Notify implements NotifyInterface { $notify_list = $this->configFactory->get('update.settings')->get('notification.emails'); if (!empty($notify_list)) { $frequency = $this->configFactory->get('automatic_updates.settings')->get('check_frequency'); - $last_check = $this->state->get('automatic_updates.last_check') ?: 0; + $last_check = $this->state->get('automatic_updates.notify_last_check') ?: 0; if (($this->time->getRequestTime() - $last_check) > $frequency) { - $this->state->set('automatic_updates.last_check', $this->time->getRequestTime()); + $this->state->set('automatic_updates.notify_last_check', $this->time->getRequestTime()); $params['subject'] = new PluralTranslatableMarkup( count($messages), -- GitLab