fix(sentinel): lock push dedupe decisions

Guard Sentinel push hash checks and cache updates with a server-scoped atomic cache lock to prevent concurrent duplicate dispatches.
This commit is contained in:
Andras Bacsai committed 2026-05-26 14:12:56 +02:00
1 parent 7677fac2f5
commit b5be9fe9e8
2 files changed
+22 -9

No files matched your search

@@ -90,6 +90,16 @@ it('rejects malformed sentinel payloads before touching server state', function
'empty containers' => [['containers' => []]],
]);
it('guards the dedupe decision with a server scoped atomic cache lock', function () {
$controller = file_get_contents(app_path('Http/Controllers/Api/SentinelController.php'));
expect($controller)
->toContain('$lockKey = "sentinel:push-lock:{$server->id}";')
->toContain('Cache::lock($lockKey, 10)->block(5, function () use ($hashKey, $forceKey, $hash): bool')
->toContain('Cache::put($hashKey, $hash, now()->addDay())')
->toContain("Cache::put(\$forceKey, true, config('constants.sentinel.push_force_interval_seconds', 300))");
});
it('dispatches the job when container state changes', function () use ($running) {
pushSentinel($this->token, sentinelPayload($running()))->assertOk();