aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg
diff options
context:
space:
mode:
authorDennis Fink2026-10-30 13:38:00 +0100
committerDennis Fink2026-10-30 13:38:00 +0100
commit33567a493a18c3a8e17e3715874d49943da494a6 (patch)
tree453a85920e0aa17a7fb9895631cbc11a1b3beb88 /webmentions_ssg
parentf6d96df2c3aecb51ca97426efddb101dce6350d7 (diff)
downloadwebmentions-ssg-33567a493a18c3a8e17e3715874d49943da494a6.tar.gz
webmentions-ssg-33567a493a18c3a8e17e3715874d49943da494a6.zip
fix(sender): prevent concurrent duplicate sends
Serialize delivery attempts per Webmention so duplicate queued tasks cannot send the same revision concurrently or consume additional retry attempts. Scope locks by Webmention UUID so unrelated deliveries can still run in parallel.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/tasks/sender.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py
index 4aa59ee..a4a8367 100644
--- a/webmentions_ssg/tasks/sender.py
+++ b/webmentions_ssg/tasks/sender.py
@@ -13,6 +13,7 @@ import httpx
import sqlalchemy as sa
from bs4 import BeautifulSoup
from flask import current_app
+from huey.exceptions import TaskLockedException
from .. import APP_NAME, VERSION
from .. import DATABASE as db
@@ -308,6 +309,20 @@ def send_webmention(webmention_uuid: uuid.UUID) -> None:
:param webmention_uuid: Identifier of the sent Webmention to process.
"""
+ # Huey locks have static names when used as decorators. Acquire one keyed by
+ # UUID inside the task so different Webmentions can still send in parallel.
+ # The pending/retry checks must happen *under* this lock.
+ try:
+ with huey.lock_task(f"send-webmention-{webmention_uuid}"):
+ send_webmention_task(webmention_uuid)
+ except TaskLockedException:
+ # Another worker is already sending this Webmention. The active worker
+ # owns its result; a later scan will requeue it if it remains pending.
+ return
+
+
+def send_webmention_task(webmention_uuid: uuid.UUID) -> None:
+ """Process a Webmention while holding its per-UUID task lock."""
webmention = db.session.get(SentWebmention, webmention_uuid)
if webmention is None: