Skip to content

A free open source IT asset/license management system

Fixed #19853 - added RetriesTransientHttpErrors

snipe624bf698b9ce
diff --git a/app/SyncAdapters/Addigy/AddigyClient.php b/app/SyncAdapters/Addigy/AddigyClient.php
index 834d9004ba..cdd6416c1b 100644
--- a/app/SyncAdapters/Addigy/AddigyClient.php
+++ b/app/SyncAdapters/Addigy/AddigyClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Addigy;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -25,6 +26,8 @@ use Illuminate\Support\Facades\Http;
*/
class AddigyClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $clientId,
@@ -73,13 +76,15 @@ class AddigyClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withHeaders([
- 'client-id' => $this->clientId,
- 'client-secret' => $this->clientSecret,
- ])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders([
+ 'client-id' => $this->clientId,
+ 'client-secret' => $this->clientSecret,
+ ])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php
index 9ce399fcea..8026d20d02 100644
--- a/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php
+++ b/app/SyncAdapters/AppleBusinessManager/AppleBusinessManagerClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\AppleBusinessManager;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Firebase\JWT\JWT;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -26,6 +27,8 @@ use Illuminate\Support\Str;
*/
class AppleBusinessManagerClient
{
+ use RetriesTransientHttpErrors;
+
private const APPLE_AUDIENCE = 'https://account.apple.com/auth/oauth2/v2/token';
private const APPLE_TOKEN_ENDPOINT = 'https://account.apple.com/auth/oauth2/v2/token';
@@ -231,29 +234,13 @@ class AppleBusinessManagerClient
*/
private function request(): PendingRequest
{
- return Http::baseUrl($this->apiBaseUrl())
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->bearer())
- ->acceptJson()
- ->timeout(30)
- ->retry(
- times: 8,
- sleepMilliseconds: function (int $attempt, \Exception $e): int {
- if ($e instanceof \Illuminate\Http\Client\RequestException && $e->response->status() === 429) {
- $retryAfter = (int) ($e->response->header('Retry-After') ?: 0);
- if ($retryAfter > 0) {
- return min($retryAfter, 120) * 1000;
- }
- }
-
- // Exponential: 500ms, 1s, 2s, 4s, 8s, 16s, 32s, 60s
- // plus up to 250ms jitter so parallel runs don't
- // retry in lockstep.
- return min(60_000, 500 * (2 ** ($attempt - 1))) + random_int(0, 250);
- },
- when: fn(\Exception $e) => $e instanceof \Illuminate\Http\Client\ConnectionException
- || ($e instanceof \Illuminate\Http\Client\RequestException && $e->response->status() === 429),
- );
+ return $this->withTransientRetry(
+ Http::baseUrl($this->apiBaseUrl())
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->bearer())
+ ->acceptJson()
+ ->timeout(30)
+ );
}
/**
diff --git a/app/SyncAdapters/Fleet/FleetClient.php b/app/SyncAdapters/Fleet/FleetClient.php
index 20181a02d7..841fdfe803 100644
--- a/app/SyncAdapters/Fleet/FleetClient.php
+++ b/app/SyncAdapters/Fleet/FleetClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Fleet;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -14,6 +15,8 @@ use Illuminate\Support\Facades\Http;
*/
class FleetClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $token,
@@ -116,10 +119,12 @@ class FleetClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->token)
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->token)
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/GoogleWorkspace/GoogleWorkspaceClient.php b/app/SyncAdapters/GoogleWorkspace/GoogleWorkspaceClient.php
index b3ae378424..d339d41de6 100644
--- a/app/SyncAdapters/GoogleWorkspace/GoogleWorkspaceClient.php
+++ b/app/SyncAdapters/GoogleWorkspace/GoogleWorkspaceClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\GoogleWorkspace;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Firebase\JWT\JWT;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -30,6 +31,8 @@ use Illuminate\Support\Facades\Http;
*/
class GoogleWorkspaceClient
{
+ use RetriesTransientHttpErrors;
+
private const TOKEN_ENDPOINT = 'https://oauth2.googleapis.com/token';
private const ADMIN_SDK_BASE_URL = 'https://admin.googleapis.com/admin/directory/v1';
@@ -177,12 +180,12 @@ class GoogleWorkspaceClient
private function request(): PendingRequest
{
- return Http::baseUrl(self::ADMIN_SDK_BASE_URL)
- ->withToken($this->bearer())
- ->withOptions(['allow_redirects' => false])
- ->acceptJson()
- ->timeout(30)
- ->retry(3, 500, fn (\Exception $e) => $e instanceof \Illuminate\Http\Client\ConnectionException
- || ($e instanceof \Illuminate\Http\Client\RequestException && $e->response->status() === 429));
+ return $this->withTransientRetry(
+ Http::baseUrl(self::ADMIN_SDK_BASE_URL)
+ ->withToken($this->bearer())
+ ->withOptions(['allow_redirects' => false])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Intune/IntuneClient.php b/app/SyncAdapters/Intune/IntuneClient.php
index 961b359685..299481b6ff 100644
--- a/app/SyncAdapters/Intune/IntuneClient.php
+++ b/app/SyncAdapters/Intune/IntuneClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Intune;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -23,6 +24,8 @@ use Illuminate\Support\Facades\Http;
*/
class IntuneClient
{
+ use RetriesTransientHttpErrors;
+
private ?string $token = null;
public function __construct(
@@ -234,9 +237,11 @@ class IntuneClient
private function request(): PendingRequest
{
- return Http::withToken($this->bearer())
- ->withOptions(['allow_redirects' => false])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::withToken($this->bearer())
+ ->withOptions(['allow_redirects' => false])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Jamf/JamfClient.php b/app/SyncAdapters/Jamf/JamfClient.php
index 4a88be6423..a4983f78b0 100644
--- a/app/SyncAdapters/Jamf/JamfClient.php
+++ b/app/SyncAdapters/Jamf/JamfClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Jamf;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -27,6 +28,8 @@ use Illuminate\Support\Facades\Http;
*/
class JamfClient
{
+ use RetriesTransientHttpErrors;
+
private ?string $accessToken = null;
private ?int $expiresAt = null;
@@ -155,11 +158,13 @@ class JamfClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->bearer())
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->bearer())
+ ->acceptJson()
+ ->timeout(30)
+ );
}
/**
diff --git a/app/SyncAdapters/JamfPlatform/JamfPlatformClient.php b/app/SyncAdapters/JamfPlatform/JamfPlatformClient.php
index 06b2e953f6..4545f00f0a 100644
--- a/app/SyncAdapters/JamfPlatform/JamfPlatformClient.php
+++ b/app/SyncAdapters/JamfPlatform/JamfPlatformClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\JamfPlatform;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -36,6 +37,8 @@ use Illuminate\Support\Facades\Http;
*/
class JamfPlatformClient
{
+ use RetriesTransientHttpErrors;
+
private ?string $accessToken = null;
public function __construct(
@@ -111,12 +114,14 @@ class JamfPlatformClient
*/
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->bearer())
- ->withHeaders(['X-Environment-Id' => $this->environmentId])
- ->acceptJson()
- ->timeout(60);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->bearer())
+ ->withHeaders(['X-Environment-Id' => $this->environmentId])
+ ->acceptJson()
+ ->timeout(60)
+ );
}
/**
diff --git a/app/SyncAdapters/JamfSchool/JamfSchoolClient.php b/app/SyncAdapters/JamfSchool/JamfSchoolClient.php
index 5692d59dc2..0d079ad74c 100644
--- a/app/SyncAdapters/JamfSchool/JamfSchoolClient.php
+++ b/app/SyncAdapters/JamfSchool/JamfSchoolClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\JamfSchool;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -19,6 +20,8 @@ use Illuminate\Support\Facades\Http;
*/
class JamfSchoolClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $networkId,
@@ -81,10 +84,12 @@ class JamfSchoolClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withBasicAuth($this->networkId, $this->apiKey)
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withBasicAuth($this->networkId, $this->apiKey)
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/JumpCloud/JumpCloudClient.php b/app/SyncAdapters/JumpCloud/JumpCloudClient.php
index 22fd64e583..518def209f 100644
--- a/app/SyncAdapters/JumpCloud/JumpCloudClient.php
+++ b/app/SyncAdapters/JumpCloud/JumpCloudClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\JumpCloud;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -18,6 +19,8 @@ use Illuminate\Support\Facades\Http;
*/
class JumpCloudClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $apiKey,
@@ -60,10 +63,12 @@ class JumpCloudClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withHeaders(['x-api-key' => $this->apiKey])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders(['x-api-key' => $this->apiKey])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Kandji/KandjiClient.php b/app/SyncAdapters/Kandji/KandjiClient.php
index 51d172ae17..ea69216d91 100644
--- a/app/SyncAdapters/Kandji/KandjiClient.php
+++ b/app/SyncAdapters/Kandji/KandjiClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Kandji;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -14,6 +15,8 @@ use Illuminate\Support\Facades\Http;
*/
class KandjiClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $token,
@@ -111,10 +114,12 @@ class KandjiClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->token)
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->token)
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/KaseyaVsa10/KaseyaVsa10Client.php b/app/SyncAdapters/KaseyaVsa10/KaseyaVsa10Client.php
index 34c0f1c0e6..524e0e8655 100644
--- a/app/SyncAdapters/KaseyaVsa10/KaseyaVsa10Client.php
+++ b/app/SyncAdapters/KaseyaVsa10/KaseyaVsa10Client.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\KaseyaVsa10;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -28,6 +29,8 @@ use Illuminate\Support\Facades\Http;
*/
class KaseyaVsa10Client
{
+ use RetriesTransientHttpErrors;
+
private ?string $basicAuth = null;
public function __construct(
@@ -140,11 +143,13 @@ class KaseyaVsa10Client
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/').'/api/v3')
- ->withOptions(['allow_redirects' => false])
- ->withHeaders(['Authorization' => 'Basic '.$this->basicAuth()])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/').'/api/v3')
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders(['Authorization' => 'Basic '.$this->basicAuth()])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
/**
diff --git a/app/SyncAdapters/Landscape/LandscapeClient.php b/app/SyncAdapters/Landscape/LandscapeClient.php
index bc5b141aba..b922477ceb 100644
--- a/app/SyncAdapters/Landscape/LandscapeClient.php
+++ b/app/SyncAdapters/Landscape/LandscapeClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Landscape;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -14,11 +15,12 @@ use Illuminate\Support\Facades\Http;
*/
class LandscapeClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $token,
- ) {
- }
+ ) {}
/**
* Stream every computer in the account, one page at a time.
@@ -51,17 +53,19 @@ class LandscapeClient
// and null once the caller has walked the full list. Prefer
// that signal over offset arithmetic so we stop as soon as
// the server says we are done.
- $hasNext = !empty($response['next'] ?? null);
+ $hasNext = ! empty($response['next'] ?? null);
$offset += $perPage;
} while ($hasNext);
}
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->token)
- ->acceptJson()
- ->timeout(60);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->token)
+ ->acceptJson()
+ ->timeout(60)
+ );
}
}
diff --git a/app/SyncAdapters/MerakiSystemsManager/MerakiClient.php b/app/SyncAdapters/MerakiSystemsManager/MerakiClient.php
index b0f1c3bd6a..60429be970 100644
--- a/app/SyncAdapters/MerakiSystemsManager/MerakiClient.php
+++ b/app/SyncAdapters/MerakiSystemsManager/MerakiClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\MerakiSystemsManager;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Http\Client\Response;
use Illuminate\Support\Facades\Http;
@@ -21,6 +22,8 @@ use Illuminate\Support\Facades\Http;
*/
class MerakiClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $apiKey,
@@ -104,10 +107,12 @@ class MerakiClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withHeaders(['X-Cisco-Meraki-API-Key' => $this->apiKey])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders(['X-Cisco-Meraki-API-Key' => $this->apiKey])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Mosyle/MosyleClient.php b/app/SyncAdapters/Mosyle/MosyleClient.php
index 8144401079..400d58332b 100644
--- a/app/SyncAdapters/Mosyle/MosyleClient.php
+++ b/app/SyncAdapters/Mosyle/MosyleClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Mosyle;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -33,6 +34,8 @@ use Illuminate\Support\Facades\Http;
*/
class MosyleClient
{
+ use RetriesTransientHttpErrors;
+
// Mosyle Manager splits devices by OS, which is a required option
// on /listdevices. A full-tenant pull iterates each OS.
private const DEVICE_OSES = [
@@ -161,11 +164,13 @@ class MosyleClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->bearer())
- ->acceptJson()
- ->asJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->bearer())
+ ->acceptJson()
+ ->asJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/MosyleBusiness/MosyleBusinessClient.php b/app/SyncAdapters/MosyleBusiness/MosyleBusinessClient.php
index f39c08dd42..fa6da992b3 100644
--- a/app/SyncAdapters/MosyleBusiness/MosyleBusinessClient.php
+++ b/app/SyncAdapters/MosyleBusiness/MosyleBusinessClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\MosyleBusiness;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -36,6 +37,8 @@ use Illuminate\Support\Facades\Http;
*/
class MosyleBusinessClient
{
+ use RetriesTransientHttpErrors;
+
// Mosyle Business splits devices by OS, which is a required option
// on /devices list. A full-tenant pull iterates each OS. Note that
// Business uses `mac` not `macos` (Manager uses `macos`).
@@ -171,14 +174,16 @@ class MosyleBusinessClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withHeaders([
- 'accessToken' => $this->accessToken,
- 'Authorization' => 'Bearer '.$this->bearer(),
- ])
- ->acceptJson()
- ->asJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders([
+ 'accessToken' => $this->accessToken,
+ 'Authorization' => 'Bearer '.$this->bearer(),
+ ])
+ ->acceptJson()
+ ->asJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/NinjaOne/NinjaOneClient.php b/app/SyncAdapters/NinjaOne/NinjaOneClient.php
index 0310e26779..2d5781320a 100644
--- a/app/SyncAdapters/NinjaOne/NinjaOneClient.php
+++ b/app/SyncAdapters/NinjaOne/NinjaOneClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\NinjaOne;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -22,6 +23,8 @@ use Illuminate\Support\Facades\Http;
*/
class NinjaOneClient
{
+ use RetriesTransientHttpErrors;
+
private ?string $token = null;
public function __construct(
@@ -111,10 +114,12 @@ class NinjaOneClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->bearer())
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->bearer())
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Osctrl/OsctrlClient.php b/app/SyncAdapters/Osctrl/OsctrlClient.php
index 859c26c2e8..0b0a4de0db 100644
--- a/app/SyncAdapters/Osctrl/OsctrlClient.php
+++ b/app/SyncAdapters/Osctrl/OsctrlClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Osctrl;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -21,6 +22,8 @@ use Illuminate\Support\Facades\Http;
*/
class OsctrlClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $token,
@@ -51,10 +54,12 @@ class OsctrlClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->token)
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->token)
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Traits/RetriesTransientHttpErrors.php b/app/SyncAdapters/Traits/RetriesTransientHttpErrors.php
new file mode 100644
index 0000000000..1502b77c77
--- /dev/null
+++ b/app/SyncAdapters/Traits/RetriesTransientHttpErrors.php
@@ -0,0 +1,51 @@
+<?php
+
+namespace App\SyncAdapters\Traits;
+
+use Illuminate\Http\Client\ConnectionException;
+use Illuminate\Http\Client\PendingRequest;
+use Illuminate\Http\Client\RequestException;
+
+/**
+ * Transient-error retry policy for sync-adapter HTTP clients. Attaches
+ * exponential backoff + jitter to a PendingRequest, with the retry
+ * window honoring 429 Retry-After up to 120 seconds. Applied through
+ * every client's base request() helper so one dropped connection or
+ * throttled page does not abort a scheduled pull.
+ *
+ * ConnectionException covers DNS, TCP, SSL, and mid-transfer drops
+ * (including cURL error 18 "transfer closed with outstanding read data
+ * remaining," which is the specific failure mode from issue #19853 that
+ * killed a Jamf pull on page 37 of 38).
+ *
+ * The policy stays off 4xx/5xx aside from 429 so adapter-side
+ * misconfiguration (bad filter shape, missing permission, auth drift)
+ * still surfaces immediately instead of running down the retry budget
+ * before failing. Writes that build their own Http:: calls (OAuth
+ * token exchanges, PATCHes against write-only endpoints) stay outside
+ * this policy unless they also route through request().
+ */
+trait RetriesTransientHttpErrors
+{
+ protected function withTransientRetry(PendingRequest $request, int $times = 8): PendingRequest
+ {
+ return $request->retry(
+ times: $times,
+ sleepMilliseconds: function (int $attempt, \Throwable $e): int {
+ if ($e instanceof RequestException && $e->response->status() === 429) {
+ $retryAfter = (int) ($e->response->header('Retry-After') ?: 0);
+ if ($retryAfter > 0) {
+ return min($retryAfter, 120) * 1000;
+ }
+ }
+
+ // 500ms, 1s, 2s, 4s, 8s, 16s, 32s, 60s plus up to 250ms
+ // jitter so parallel instance runs do not retry in
+ // lockstep.
+ return min(60_000, 500 * (2 ** ($attempt - 1))) + random_int(0, 250);
+ },
+ when: fn (\Throwable $e): bool => $e instanceof ConnectionException
+ || ($e instanceof RequestException && $e->response->status() === 429),
+ );
+ }
+}
diff --git a/app/SyncAdapters/Unifi/UnifiClient.php b/app/SyncAdapters/Unifi/UnifiClient.php
index 7ffcb6ec3f..af27911297 100644
--- a/app/SyncAdapters/Unifi/UnifiClient.php
+++ b/app/SyncAdapters/Unifi/UnifiClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Unifi;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -26,6 +27,8 @@ use Illuminate\Support\Facades\Http;
*/
class UnifiClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $apiKey,
@@ -90,10 +93,12 @@ class UnifiClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withHeaders(['X-API-KEY' => $this->apiKey])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders(['X-API-KEY' => $this->apiKey])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/UnifiAccess/UnifiAccessClient.php b/app/SyncAdapters/UnifiAccess/UnifiAccessClient.php
index 82e92ef219..841cdde3e8 100644
--- a/app/SyncAdapters/UnifiAccess/UnifiAccessClient.php
+++ b/app/SyncAdapters/UnifiAccess/UnifiAccessClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\UnifiAccess;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -29,6 +30,8 @@ use Illuminate\Support\Facades\Http;
*/
class UnifiAccessClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $apiToken,
@@ -66,10 +69,12 @@ class UnifiAccessClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->apiToken)
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->apiToken)
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/WorkspaceOne/WorkspaceOneClient.php b/app/SyncAdapters/WorkspaceOne/WorkspaceOneClient.php
index a28e359e72..8636f4846d 100644
--- a/app/SyncAdapters/WorkspaceOne/WorkspaceOneClient.php
+++ b/app/SyncAdapters/WorkspaceOne/WorkspaceOneClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\WorkspaceOne;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -23,6 +24,8 @@ use Illuminate\Support\Facades\Http;
*/
class WorkspaceOneClient
{
+ use RetriesTransientHttpErrors;
+
private ?string $token = null;
public function __construct(
@@ -130,11 +133,13 @@ class WorkspaceOneClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->apiBaseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withToken($this->bearer())
- ->withHeaders(['aw-tenant-code' => $this->tenantCode])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->apiBaseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withToken($this->bearer())
+ ->withHeaders(['aw-tenant-code' => $this->tenantCode])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/app/SyncAdapters/Zentral/ZentralClient.php b/app/SyncAdapters/Zentral/ZentralClient.php
index 4f7393819a..ba28d25f03 100644
--- a/app/SyncAdapters/Zentral/ZentralClient.php
+++ b/app/SyncAdapters/Zentral/ZentralClient.php
@@ -2,6 +2,7 @@
namespace App\SyncAdapters\Zentral;
+use App\SyncAdapters\Traits\RetriesTransientHttpErrors;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
@@ -19,6 +20,8 @@ use Illuminate\Support\Facades\Http;
*/
class ZentralClient
{
+ use RetriesTransientHttpErrors;
+
public function __construct(
private readonly string $baseUrl,
private readonly string $token,
@@ -57,10 +60,12 @@ class ZentralClient
private function request(): PendingRequest
{
- return Http::baseUrl(rtrim($this->baseUrl, '/'))
- ->withOptions(['allow_redirects' => false])
- ->withHeaders(['Authorization' => 'Token '.$this->token])
- ->acceptJson()
- ->timeout(30);
+ return $this->withTransientRetry(
+ Http::baseUrl(rtrim($this->baseUrl, '/'))
+ ->withOptions(['allow_redirects' => false])
+ ->withHeaders(['Authorization' => 'Token '.$this->token])
+ ->acceptJson()
+ ->timeout(30)
+ );
}
}
diff --git a/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php b/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php
index d3f2db13a6..e51edf4fe4 100644
--- a/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php
+++ b/tests/Feature/SyncAdapters/Jamf/JamfAdapterTest.php
@@ -7,8 +7,10 @@ use App\Models\SyncAdapterConfig;
use App\Models\SyncAdapterInstance;
use App\SyncAdapters\Jamf\JamfAdapter;
use App\SyncAdapters\SyncAdapter;
+use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\Http;
+use Illuminate\Support\Sleep;
use Tests\TestCase;
/**
@@ -227,6 +229,66 @@ class JamfAdapterTest extends TestCase
$this->assertTrue($record->extra['jamf_mobile_supervised']);
}
+ public function test_retries_connection_error_on_a_paginated_page()
+ {
+ // Regression test for #19853. A real customer's Jamf pull of
+ // ~3,800 computers aborted on page 37 of 38 with
+ // "cURL error 18: transfer closed with outstanding read data
+ // remaining." Laravel surfaces that as ConnectionException from
+ // the HTTP client, which the trait retries. Fake Sleep so the
+ // backoff doesn't actually block the test.
+ Sleep::fake();
+
+ $adapter = $this->configuredJamfAdapter();
+
+ $attempts = 0;
+ Http::fake([
+ '*/api/oauth/token' => $this->jamfTokenResponse(),
+ '*/api/v1/computers-inventory*' => function () use (&$attempts) {
+ $attempts++;
+ if ($attempts === 1) {
+ throw new ConnectionException('cURL error 18: transfer closed with outstanding read data remaining');
+ }
+
+ return Http::response([
+ 'totalCount' => 1,
+ 'results' => [$this->jamfComputer(id: 1, name: 'retried-mac')],
+ ]);
+ },
+ ]);
+
+ $records = iterator_to_array($adapter->pull());
+
+ $this->assertCount(1, $records);
+ $this->assertSame('retried-mac', $records[0]->hostname);
+ $this->assertSame(2, $attempts, 'JamfClient should have retried the dropped page once.');
+ }
+
+ public function test_retries_on_429_and_honors_retry_after_header()
+ {
+ // Jamf Pro doesn't throttle with 429 by default, but Graph does
+ // and the trait is shared, so prove Jamf's wrapper reads
+ // Retry-After the same way.
+ Sleep::fake();
+
+ $adapter = $this->configuredJamfAdapter();
+
+ Http::fake([
+ '*/api/oauth/token' => $this->jamfTokenResponse(),
+ '*/api/v1/computers-inventory*' => Http::sequence()
+ ->push(['detail' => 'rate limited'], 429, ['Retry-After' => '1'])
+ ->push([
+ 'totalCount' => 1,
+ 'results' => [$this->jamfComputer(id: 2, name: 'throttled-mac')],
+ ], 200),
+ ]);
+
+ $records = iterator_to_array($adapter->pull());
+
+ $this->assertCount(1, $records);
+ $this->assertSame('throttled-mac', $records[0]->hostname);
+ }
+
private function configuredJamfAdapter(bool $includeMobile = false): JamfAdapter
{
$instance = SyncAdapterInstance::where('slug', 'jamf')->firstOrFail();