Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/Services/Social/ConnectionVerifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use App\Services\Social\Discord\DiscordClient;
use App\Services\Social\Meta\GraphError;
use App\Services\Social\Telegram\TelegramApi;
use Illuminate\Contracts\Cache\LockTimeoutException;
use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
Expand Down Expand Up @@ -204,7 +205,18 @@ public function refreshToken(SocialAccount $account): bool
$lock = Cache::lock("token_refresh:{$account->id}", self::REFRESH_LOCK_SECONDS);

if (! $lock->get()) {
// Another process is already refreshing this token.
// Another process is already refreshing this token. Wait for it
// to finish before re-reading the row: re-reading immediately
// usually finds the not-yet-persisted old token (both jobs fire
// on the same cron tick) and needlessly fails the caller with a
// transient error even though a fresh token lands moments later.
try {
$lock->block(15);
$lock->release();
} catch (LockTimeoutException) {
// Fall through — the row is re-read either way.
}

$account->refresh();

if ($account->is_token_expired) {
Expand Down