From 25d98a4ee3bed8f7983ac579beceb3bc390cb4ad Mon Sep 17 00:00:00 2001 From: AIDev Bot Date: Tue, 17 Nov 2026 07:04:57 +0000 Subject: [PATCH] Apple notification forward never blocks our own processing The APPLE_PROXY_HOST forward runs before the notice is stored, with no timeout and no error handling. When the target is down, every notice throws, Apple gets a 500 and nothing is stored or sent to AppsFlyer. cdlbackend (analytics.mapo.la/webhooks/13) and dmvbackend (/42) have been in that state since 2025-06-16. Now the forward waits at most proxy_timeout seconds (APPLE_PROXY_TIMEOUT, default 5) and a failure is only logged as a warning. Co-Authored-By: Claude Opus 5.5 --- config/appstore-server-notifications.php | 4 ++++ src/ProxyHelper.php | 7 +++++++ src/WebhooksController.php | 10 +++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/config/appstore-server-notifications.php b/config/appstore-server-notifications.php index 22d8735..2b1544e 100644 --- a/config/appstore-server-notifications.php +++ b/config/appstore-server-notifications.php @@ -23,4 +23,8 @@ return [ // 'did_change_renewal_status' => \App\Jobs\AppstoreNotifications\HandleDidChangeRenewalStatus::class, ], 'proxy_host' => env('APPLE_PROXY_HOST'), + /* + * Seconds to wait for the proxy_host before giving up (the forward never blocks our own processing). + */ + 'proxy_timeout' => env('APPLE_PROXY_TIMEOUT', 5), ]; diff --git a/src/ProxyHelper.php b/src/ProxyHelper.php index 9188cdd..81044e8 100644 --- a/src/ProxyHelper.php +++ b/src/ProxyHelper.php @@ -23,6 +23,9 @@ class ProxyHelper { private $addQuery; + //Timeout in seconds (connect and total), none if empty + private $timeout; + //If needed add cookies support with: // - PendingRequest->withCookies // - Request->hasCookie @@ -53,6 +56,8 @@ class ProxyHelper { public function preserveQuery($preserve){ $this->addQuery = $preserve; return $this; } + public function withTimeout($seconds){ $this->timeout = $seconds; return $this; } + public function getResponse($url){ $info = $this->getRequestInfo(); @@ -60,6 +65,8 @@ class ProxyHelper { $http = $this->createHttp($info['type']); $http = $this->setAuth($http, $info['token']); $http = $this->setHeaders($http); + if($this->timeout) + $http = $http->timeout((int)$this->timeout)->withOptions(['connect_timeout' => (int)$this->timeout]); if($this->addQuery && $info['query']) $url = $url.'?'.http_build_query($info['query']); diff --git a/src/WebhooksController.php b/src/WebhooksController.php index 3d0935d..da1d751 100644 --- a/src/WebhooksController.php +++ b/src/WebhooksController.php @@ -4,6 +4,7 @@ namespace Appvise\AppStoreNotifications; use Appvise\AppStoreNotifications\ProxyHelperFacade; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Log; use Appvise\AppStoreNotifications\Model\NotificationType; use Appvise\AppStoreNotifications\Model\AppleNotification; use Appvise\AppStoreNotifications\Exceptions\WebhookFailed; @@ -15,7 +16,14 @@ class WebhooksController { $proxy_host = config('appstore-server-notifications.proxy_host'); if (!empty($proxy_host)) { - ProxyHelperFacade::CreateProxy($request)->toUrl($proxy_host); + // The forward must never stop our own processing: short timeout, errors only logged. + try { + ProxyHelperFacade::CreateProxy($request) + ->withTimeout(config('appstore-server-notifications.proxy_timeout', 5)) + ->toUrl($proxy_host); + } catch (\Throwable $e) { + Log::warning("Apple notification forward to {$proxy_host} failed: " . $e->getMessage()); + } } $jobConfigKey = NotificationType::{$request->input('notification_type')}();