The worker thread called the SSRF checks, which read current_app.config, without an app context, so every incoming and outgoing webmention failed with 'Working outside of application context'. A teardown_appcontext hook also stopped the worker whenever a request ended. Pass the app to WebmentionWorker and run each poll in app.app_context(), like SyndicationWorker, and drop the teardown hook. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1.4 KiB
1.4 KiB
v2.6.8: Webmention worker app context
Problem
Production webmention #1 (Bridgy, reply from Mastodon to note 20261101162512)
was stored with validation_status = 'error':
"Working outside of application context". Both outgoing queue items had the
same error and were on their last retry.
Causes
webmention_ssrf.safe_resolve()readscurrent_app.config['DEV_MODE'].WebmentionWorkeris a plain thread with no Flask app context, so everyvalidate_url_for_fetch()call raisedRuntimeError, for both validation (incoming) and endpoint discovery and sending (outgoing).create_app()registered ateardown_appcontexthandler that calledwebmention_worker.stop(). Teardown runs whenever any app context ends (every request), so the worker stopped soon after startup.
Fix
WebmentionWorkertakes the Flask app and runs each poll insideapp.app_context(), asSyndicationWorkeralready does.- The teardown handler is removed. The worker is a daemon thread and ends with the process.
Tests
tests/test_webmention_worker.py: an outgoing send completes through the
worker thread, and the worker is still alive after an app context and a
request end. Both fail without the fix.
Production data
After deploying, reset webmention 1 to validation_status = 'pending' and the
two queue items to retry_count = 0, next_retry_at = NULL so the worker
processes them again.