Skip to content

fix(CloudflarePurger): catch TransferException so connect timeouts are logged - #17

Merged
Zippybonzo merged 2 commits into
mainfrom
sentry/cloudflare-purge-connect-timeout
Sep 11, 2026
Merged

Zippybonzo merged 2 commits into
mainfrom
sentry/cloudflare-purge-connect-timeout

Conversation

@claude

@claude claude Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Requested by Thomas · Slack thread

Addresses Sentry MEDIAWIKI-CCK (64 events, 23 users affected).

Before: Every edit and file upload queues a Cloudflare cache purge as a deferred update. When the request to api.cloudflare.com failed to connect within the 3-second connect timeout — 0 bytes received — the error was not caught. purge() has a handler written to log exactly this and return false, but it catches RequestException, and Guzzle 7 raises a ConnectException for a connect or DNS timeout. So the exception sailed past the handler, aborted the deferred update, and surfaced as an unhandled error in Sentry, with no "Cloudflare purge failed" line in the logs to say what had gone wrong.

After: A connect or DNS timeout is caught by the same handler as any other transfer failure. The purge logs Cloudflare purge failed with the hook, the purge body and the error message, returns false, and the deferred update finishes normally instead of throwing. The Sentry noise stops and the failure becomes visible where it was meant to be visible.

How: One-line change in includes/CloudflarePurger.php — the catch in purge() now takes GuzzleHttp\Exception\TransferException instead of GuzzleHttp\Exception\RequestException (the use statement changed to match), with a comment recording why. In Guzzle 7 both ConnectException and RequestException extend TransferException directly; ConnectException is a sibling of RequestException, not a subclass, so it was never covered. Verified against guzzle/guzzle 7.9 source: class ConnectException extends TransferException implements NetworkExceptionInterface and class RequestException extends TransferException implements RequestExceptionInterface. The method is otherwise untouched.

What this does not fix

  • The cache still goes stale. This restores the logging and stops the errors; it does not deliver the purge. On the affected wikis, a user who edits a page or uploads a file may still be served the old version from Cloudflare afterwards.
  • The root cause is connectivity, not this catch block. Egress from the wiki hosts to api.cloudflare.com is failing to establish a connection within 3 seconds. That is worth investigating separately — it is why the purges are failing at all.
  • Fire-and-forget is the wrong shape for this. The purge runs as a deferred update with no retry, so any transient timeout silently loses a purge for good. Making it a retryable job would let a purge that times out once still land.

Verification

  • php -l includes/CloudflarePurger.php → No syntax errors detected in includes/CloudflarePurger.php
  • composer test (the repo's own script: parallel-lint, minus-x, phpcs) →
    PHP 8.4.19 | 10 parallel jobs
    ............                                                 12/12 (100%)
    Checked 12 files in 0.1 seconds
    No syntax error found
    MinusX
    Processing /home/claude/wikioasismagic...
    All good!
    ............ 12 / 12 (100%)
    Time: 300ms; Memory: 8MB
    

Note that composer test in this repo is lint and style only — parallel-lint, MinusX and PHPCS. There are no unit tests here and no test coverage of CloudflarePurger, so the run above says the change is syntactically and stylistically clean, not that the new catch was exercised. The behaviour is established from the Sentry stack traces and from Guzzle's class hierarchy as quoted above.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AiEBkhzV1z9bEykvEU9U8j


Generated by Claude Code

…e logged

purge() caught GuzzleHttp\Exception\RequestException. In Guzzle 7,
ConnectException extends TransferException directly and is a sibling of
RequestException, not a subclass of it, so a connect or DNS timeout to
api.cloudflare.com never reached the handler written to log it. Instead it
escaped purge(), aborted the deferred update and was reported as an
unhandled error.

Catching TransferException covers both branches, so a timed-out purge
produces the intended "Cloudflare purge failed" log line and a false
return. The purge is still lost - the stale-cache and egress-connectivity
problems behind these timeouts are separate.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AiEBkhzV1z9bEykvEU9U8j
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: d254f495-b46f-4cf6-8b99-46f6515063ab

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@claude

claude Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

The failing check call-mediawiki-tests-workflow (REL1_46, 8.4, 84, false, false, true, false) / REL1_46 | PHP 8.4 is not caused by this PR.

It fails at the Composer install step, before any lint or test runs:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires mediawiki/mediawiki-codesniffer 51.0.0 -> satisfiable by mediawiki/mediawiki-codesniffer[v51.0.0].
    - mediawiki/mediawiki-codesniffer v51.0.0 requires squizlabs/php_codesniffer 3.13.5 -> found squizlabs/php_codesniffer[3.13.5] but these were not loaded, because they are affected by security advisories ("PKSA-rdkp-vv9z-mjkg").

PKSA-rdkp-vv9z-mjkg (OS command injection, affects squizlabs/php_codesniffer <3.13.6) was published 2026-08-05, so Composer now refuses to install the pinned dev dependency. This PR only changes includes/CloudflarePurger.php; the job never reaches a step that runs our code.

The same check is red on main: the most recent run on main (0953603, this PR's base commit) failed at the same Composer install step with the identical message — https://github.com/WikiOasis/WikiOasisMagic/actions/runs/32478905558

No fix is included here. Upstream has one: mediawiki/mediawiki-codesniffer v51.0.1 requires squizlabs/php_codesniffer 3.13.6, which the advisory does not cover, so bumping the require-dev pin from 51.0.0 to 51.0.1 should unblock installs. That belongs in its own change rather than in this PR.


Generated by Claude Code

51.0.0 pins squizlabs/php_codesniffer 3.13.5, which Composer now refuses to
install because of advisory PKSA-rdkp-vv9z-mjkg (CVE-2026-67434, OS command
injection, affects <3.13.6). CI fails at the Composer install step before any
test runs. 51.0.1 requires php_codesniffer 3.13.6, outside the advisory range.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AiEBkhzV1z9bEykvEU9U8j
@Zippybonzo
Zippybonzo merged commit dc3024c into main Sep 11, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants