Repository navigation
Description
👟 Reproduction steps
The webhooks worker's failure branch is not concurrency-safe around the retry-threshold transition. When two failing deliveries for the same webhook are processed concurrently (two subscribed events dispatched close together), both handlers can independently cross the threshold and each enqueue a "paused" notification.
- Configure a webhook whose target returns an error (e.g. a non-existent URL or a 5xx endpoint) and subscribe it to a frequently-emitted event.
- Set
_APP_WEBHOOK_MAX_FAILED_ATTEMPTSto10(default) and driveattemptsto9. - Emit two subscribed events in quick succession so two
v1-webhooksworker handlers run concurrently for the same webhook. - Observe the notification recipient's inbox / notification queue.
👍 Expected behavior
Crossing the failure threshold is a single logical event, so exactly one "webhook paused" alert should be sent per pause cycle.
👎 Actual Behavior
Both concurrent handlers can send a "paused" alert, producing duplicate notifications for one threshold transition.
Root cause (src/Appwrite/Platform/Workers/Webhooks.php, lines 164–192 — permalink below):
$dbForPlatform->increaseDocumentAttribute('webhooks', $webhook->getId(), 'attempts', 1); // L165 atomic
$webhook = $dbForPlatform->getDocument('webhooks', $webhook->getId()); // L166 reload
$attempts = $webhook->getAttribute('attempts'); // L167
// ...
if ($attempts >= \intval(System::getEnv('_APP_WEBHOOK_MAX_FAILED_ATTEMPTS', '10'))) { // L185
$webhook->setAttribute('enabled', false);
$updatePayload['enabled'] = false;
$this->sendAlert(...); // L188 alert BEFORE persist
}
$dbForPlatform->updateDocument('webhooks', $webhook->getId(), new Document($updatePayload)); // L191 persist enabled=falseAlthough the increment at L165 is atomic, the threshold check (L185) and sendAlert (L188) happen before enabled = false is persisted (L191). With attempts starting at 9, handler A increments to 10 and handler B to 11; both reload a document with attempts >= 10, both take the branch, and both call sendAlert. The notification deduplication key does not save this — it is:
deduplicationKey: 'webhook:' . $webhook->getId() . ':paused:' . $webhook->getUpdatedAt(),Each handler's getUpdatedAt() reflects its own increaseDocumentAttribute write (two distinct timestamps), so the two keys differ and both notifications pass deduplication.
Permalink:
appwrite/src/Appwrite/Platform/Workers/Webhooks.php
Lines 164 to 192 in 4100141
| if (!empty($curlError) || $statusCode >= 400) { | |
| $dbForPlatform->increaseDocumentAttribute('webhooks', $webhook->getId(), 'attempts', 1); | |
| $webhook = $dbForPlatform->getDocument('webhooks', $webhook->getId()); | |
| $attempts = $webhook->getAttribute('attempts'); | |
| $logs = ''; | |
| $logs .= 'URL: ' . $webhook->getAttribute('url') . "\n"; | |
| $logs .= 'Method: ' . 'POST' . "\n"; | |
| if (!empty($curlError)) { | |
| $logs .= 'CURL Error: ' . $curlError . "\n"; | |
| $logs .= 'Events: ' . implode(', ', $events) . "\n"; | |
| } else { | |
| $logs .= 'Status code: ' . $statusCode . "\n"; | |
| $logs .= 'Body: ' . "\n" . \mb_strcut($responseBody, 0, 10000) . "\n"; // Limit to 10kb | |
| } | |
| $webhook->setAttribute('logs', $logs); | |
| $updatePayload = ['logs' => $logs]; | |
| if ($attempts >= \intval(System::getEnv('_APP_WEBHOOK_MAX_FAILED_ATTEMPTS', '10'))) { | |
| $webhook->setAttribute('enabled', false); | |
| $updatePayload['enabled'] = false; | |
| $this->sendAlert($attempts, $statusCode, $webhook, $project, $dbForPlatform, $publisherForNotifications, $plan); | |
| } | |
| $dbForPlatform->updateDocument('webhooks', $webhook->getId(), new Document($updatePayload)); | |
| $dbForPlatform->purgeCachedDocument('projects', $project->getId()); |
🎲 Appwrite version
main branch (self-hosted); the code path is unchanged as of commit 4100141.
💻 Operating system
Linux
🧱 Your Environment
src/Appwrite/Platform/Workers/Webhooks.php, execute() failure branch (lines 164–192) and sendAlert() deduplication key (lines 318–321). Manifests under the concurrent v1-webhooks worker model; the webhook is still correctly paused — only the alert is duplicated.
Suggested fix: make the "cross threshold → pause → alert" transition claim-once. For example, gate sendAlert on the persisted state actually transitioning from enabled→disabled (only alert when the enabled = false write is the one that flipped it), or base the deduplication key on a stable per-pause-cycle value rather than getUpdatedAt() (which changes on every attempt increment).
Found while running Ito (AI code review, free for open source) against recently merged PRs — full analysis: https://app.ito.ai/share/98820504-87a2-4566-aa81-aee6e05be7a1.
Activity
kush2439p commentedon Aug 13, 2026
I would like to work on this issue. I have prepared #12946 with a transaction-protected enabled-to-disabled transition and regression coverage for duplicate paused alerts; please assign it to me if the approach fits the project.