Skip to content

Implement support for HTTP 429 Too Many Requests - #7760

Merged
Alkarex merged 6 commits into
FreshRSS:edgefrom
Alkarex:http-429
Jul 31, 2025
Merged

Alkarex merged 6 commits into
FreshRSS:edgefrom
Alkarex:http-429

Conversation

@Alkarex

@Alkarex Alkarex commented Jul 27, 2025 •

Copy link
Copy Markdown
Member

As well as 503 Service Unavailable.
Will obey the corresponding HTTP Retry-After header at domain level.

Will obey the corresponding HTTP `Retry-After` header at domain level.
@Alkarex Alkarex added SimplePie 🍰 RSS standard the standard is defined f.e. on https://www.rssboard.org labels Jul 27, 2025
@Alkarex Alkarex added this to the 1.27.0 milestone Jul 27, 2025
curl_setopt($fp, CURLOPT_HEADER, 1);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
// curl_setopt($fp, CURLOPT_FAILONERROR, 1); // FreshRSS removed to retrieve headers even on HTTP errors

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


/**
* @return int|bool
* @return int|false

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alkarex Alkarex linked an issue Jul 27, 2025 that may be closed by this pull request
@Alkarex Alkarex linked an issue Jul 27, 2025 that may be closed by this pull request
@Frenzie

Frenzie commented Jul 27, 2025

Copy link
Copy Markdown
Member

Even if the value it sets is more than a month? I think there's a point somewhere past let's say a week where it ceases to be meaningful (though granted, perhaps the app intends to communicate never to return again? :-)

@Alkarex

Alkarex commented Jul 27, 2025

Copy link
Copy Markdown
Member Author

Even if the value it sets is more than a month? I think there's a point somewhere past let's say a week where it ceases to be meaningful (though granted, perhaps the app intends to communicate never to return again? :-)

Yes indeed. That was my intention, but I forgot :-)

@Frenzie Frenzie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried it ('cause I'd have to set up a test server that sends out these headers or something) but it looks good. 👍

@Alkarex
Alkarex merged commit 7a0c423 into FreshRSS:edge Jul 31, 2025
@Alkarex
Alkarex deleted the http-429 branch July 31, 2025 07:17
@Alkarex Alkarex mentioned this pull request Jul 31, 2025
alexlebens pushed a commit to alexlebens/infrastructure that referenced this pull request Aug 20, 2025
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [freshrss/freshrss](https://freshrss.org/) ([source](https://github.com/FreshRSS/FreshRSS)) | minor | `1.26.3` -> `1.27.0` |

---

### Release Notes

<details>
<summary>FreshRSS/FreshRSS (freshrss/freshrss)</summary>

### [`v1.27.0`](https://github.com/FreshRSS/FreshRSS/blob/HEAD/CHANGELOG.md#2025-08-18-FreshRSS-1270)

[Compare Source](FreshRSS/FreshRSS@1.26.3...1.27.0)

- Features
  - Implement support for HTTP `429 Too Many Requests` and `503 Service Unavailable`, obey `Retry-After` [#&#8203;7760](FreshRSS/FreshRSS#7760)
  - Add sort by category title, or by feed title [#&#8203;7702](FreshRSS/FreshRSS#7702)
  - Add search operator `c:` for categories like `c:23,34` or `!c:45,56` [#&#8203;7696](FreshRSS/FreshRSS#7696)
  - Custom feed favicons [#&#8203;7646](FreshRSS/FreshRSS#7646), [#&#8203;7704](FreshRSS/FreshRSS#7704), [#&#8203;7717](FreshRSS/FreshRSS#7717),
    [#&#8203;7792](FreshRSS/FreshRSS#7792)
  - Rework fetch favicons for fewer HTTP requests [#&#8203;7767](FreshRSS/FreshRSS#7767)
  - Add more unicity criteria based on title and/or content [#&#8203;7789](FreshRSS/FreshRSS#7789)
  - Automatically restore user configuration from backup [#&#8203;7682](FreshRSS/FreshRSS#7682)
  - API add support for states in `s` parameter of `streamId` [#&#8203;7695](FreshRSS/FreshRSS#7695)
  - Improve sharing via Print [#&#8203;7728](FreshRSS/FreshRSS#7728)
  - Redirect to the login page from bookmarklet instead of 403 [#&#8203;7782](FreshRSS/FreshRSS#7782)
  - Clean local cache more often, when refreshing feeds [#&#8203;7827](FreshRSS/FreshRSS#7827)
- Security
  - Implement reauthentication (*sudo* mode) [#&#8203;7753](FreshRSS/FreshRSS#7753)
  - Add `Content-Security-Policy: frame-ancestors` [#&#8203;7677](FreshRSS/FreshRSS#7677)
  - Ensure CSP everywhere [#&#8203;7810](FreshRSS/FreshRSS#7810)
  - Show warning when unsafe CSP policy is in use [#&#8203;7804](FreshRSS/FreshRSS#7804)
  - Fix access rights when creating a new user [#&#8203;7783](FreshRSS/FreshRSS#7783)
  - Improve security of form for user details [#&#8203;7771](FreshRSS/FreshRSS#7771), [#&#8203;7786](FreshRSS/FreshRSS#7786)
  - Disallow setting non-existent theme [#&#8203;7722](FreshRSS/FreshRSS#7722)
  - Regenerate cookie ID after logging out [#&#8203;7762](FreshRSS/FreshRSS#7762)
  - Require current password when setting new password [#&#8203;7763](FreshRSS/FreshRSS#7763)
  - Add missing access checks for feed-related actions [#&#8203;7768](FreshRSS/FreshRSS#7768)
  - Strip more unsafe attributes such as `referrerpolicy`, `ping` [#&#8203;7770](FreshRSS/FreshRSS#7770)
  - Remove unneeded execution permissions [#&#8203;7802](FreshRSS/FreshRSS#7802)
- Bug fixing
  - Fix redirections when scraping from HTML [#&#8203;7654](FreshRSS/FreshRSS#7654), [#&#8203;7741](FreshRSS/FreshRSS#7741)
  - Fix multiple authentication HTTP headers [#&#8203;7703](FreshRSS/FreshRSS#7703)
  - Fix HTML queries with a single feed [#&#8203;7730](FreshRSS/FreshRSS#7730)
  - WebSub: only perform a redirection when coming from WebSub [#&#8203;7738](FreshRSS/FreshRSS#7738)
  - Include enclosures in entries’ hash [#&#8203;7719](FreshRSS/FreshRSS#7719)
    - Negative side-effect: users of the option to *automatically mark updated articles as unread* will once have some articles with enclosures re-appear as unread
  - Fix cancellation of slider exit UI [#&#8203;7705](FreshRSS/FreshRSS#7705)
  - Honor *disable update* on update page [#&#8203;7733](FreshRSS/FreshRSS#7733)
  - Fix no registration limit setting [#&#8203;7751](FreshRSS/FreshRSS#7751)
  - Fix XML encoding of sharing functions [#&#8203;7822](FreshRSS/FreshRSS#7822)
- SimplePie
  - Fix propagation of HTTP error codes [#&#8203;7670](FreshRSS/FreshRSS#7670)
  - Fix support for XML feeds with HTML entities [#&#8203;7689](FreshRSS/FreshRSS#7689), [simplepie#915](simplepie/simplepie#915)
  - Fix feeds encoded in UTF-16LE [#&#8203;7691](FreshRSS/FreshRSS#7691), [simplepie#916](simplepie/simplepie#916)
  - Various upstream contributions [simplepie#917](simplepie/simplepie#917), [simplepie#924](simplepie/simplepie#924),
    [simplepie#926](simplepie/simplepie#926), [simplepie#932](simplepie/simplepie#932), [simplepie#933](simplepie/simplepie#933)
  - Sync upstream [#&#8203;7706](FreshRSS/FreshRSS#7706), [FreshRSS/simplepie#45](FreshRSS/simplepie#45), [#&#8203;7775](FreshRSS/FreshRSS#7775),
    [FreshRSS/simplepie#50](FreshRSS/simplepie#50), [#&#8203;7824](FreshRSS/FreshRSS#7824), [#&#8203;7825](FreshRSS/FreshRSS#7825),
  - Fix regex *Backtrack limit was exhausted* in `clean_hash()` [#&#8203;7813](FreshRSS/FreshRSS#7813), [FreshRSS/simplepie#48](FreshRSS/simplepie#48)
- Deployment
  - Docker default image (Debian 12 Bookworm) updated to PHP 8.2.29 [#&#8203;7805](FreshRSS/FreshRSS#7805)
  - Docker alternative image updated to Alpine 3.22 with PHP 8.4.11 and Apache 2.4.65 [#&#8203;7740](FreshRSS/FreshRSS#7740), [#&#8203;7740](FreshRSS/FreshRSS#7740),
    [#&#8203;7803](FreshRSS/FreshRSS#7803)
  - Start supporting PHP 8.5+ [#&#8203;7787](FreshRSS/FreshRSS#7787), [#&#8203;7826](FreshRSS/FreshRSS#7826)
    - Docker Alpine dev image `:newest` updated to PHP 8.5-alpha and Apache 2.4.65 [#&#8203;7773](FreshRSS/FreshRSS#7773)
  - Docker: interpolate `FRESHRSS_INSTALL` and `FRESHRSS_USER` variables [#&#8203;7725](FreshRSS/FreshRSS#7725)
  - Docker: Reduce how much data needs to be chown/chmod’ed on container startup [#&#8203;7793](FreshRSS/FreshRSS#7793)
  - Test for database PDO typing support during install (relevant for MySQL / MariaDB with obsolete driver) [#&#8203;7651](FreshRSS/FreshRSS#7651)
- Extensions
  - Add API endpoint for extensions [#&#8203;7576](FreshRSS/FreshRSS#7576)
  - Expose the reading modes for extensions [#&#8203;7668](FreshRSS/FreshRSS#7668), [#&#8203;7688](FreshRSS/FreshRSS#7688)
  - New extension hook `before_login_btn` [#&#8203;7761](FreshRSS/FreshRSS#7761)
- UI
  - Improve *mark as read* request showing popup due to `onbeforeunload` [#&#8203;7554](FreshRSS/FreshRSS#7554)
  - Fix lazy-loading for `<video poster="...">` and `<image>` [#&#8203;7636](FreshRSS/FreshRSS#7636)
  - Avoid styling `<code>` inside of `<pre>` [#&#8203;7797](FreshRSS/FreshRSS#7797)
  - Improve confirmation logic with `data-auto-leave-validation` [#&#8203;7785](FreshRSS/FreshRSS#7785)
  - Update `chart.js` to 4.5.0 [#&#8203;7752](FreshRSS/FreshRSS#7752), [#&#8203;7816](FreshRSS/FreshRSS#7816)
  - Various UI and style improvements: [#&#8203;7616](FreshRSS/FreshRSS#7616), [#&#8203;7811](FreshRSS/FreshRSS#7811)
- I18n
  - Show translation status in README [#&#8203;7715](FreshRSS/FreshRSS#7715)
  - Improve Indonesian [#&#8203;7654](FreshRSS/FreshRSS#7654), [#&#8203;7721](FreshRSS/FreshRSS#7721)
  - Improve Persian [#&#8203;7795](FreshRSS/FreshRSS#7795)
- Misc.
  - Improve PHP code [#&#8203;7642](FreshRSS/FreshRSS#7642), [#&#8203;7665](FreshRSS/FreshRSS#7665), [#&#8203;7761](FreshRSS/FreshRSS#7761),
    [#&#8203;7781](FreshRSS/FreshRSS#7781), [#&#8203;7794](FreshRSS/FreshRSS#7794)
  - Update dev dependencies [#&#8203;7708](FreshRSS/FreshRSS#7708), [#&#8203;7709](FreshRSS/FreshRSS#7709), [#&#8203;7710](FreshRSS/FreshRSS#7710),
    [#&#8203;7711](FreshRSS/FreshRSS#7711), [#&#8203;7776](FreshRSS/FreshRSS#7776), [#&#8203;7777](FreshRSS/FreshRSS#7777)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MS4zNS4wIiwidXBkYXRlZEluVmVyIjoiNDEuMzUuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiaW1hZ2UiXX0=-->

Reviewed-on: https://gitea.alexlebens.dev/alexlebens/infrastructure/pulls/1253
Co-authored-by: Renovate Bot <renovate-bot@alexlebens.net>
Co-committed-by: Renovate Bot <renovate-bot@alexlebens.net>
@DamonHD

DamonHD commented Oct 25, 2026

Copy link
Copy Markdown

Even if the value it sets is more than a month? I think there's a point somewhere past let's say a week where it ceases to be meaningful (though granted, perhaps the app intends to communicate never to return again? :-)

Yes indeed. That was my intention, but I forgot :-)

Do you now have the retry interval capped at 1h maximum? If so that is way too short, eg for monthly podcast episodes. I suggest a cap of no less than a day, which won't hideously break things even for very badly configured feeds.

For example there is a FreshRSS/1.30.0 instance currently polling me hourly on a feed that I have deliberately kept unchanged for several months as part of a larger attempt to reduce compute/bandwidth/carbon waste. The normal cadence of that feed is roughly monthly, but it doesn't matter at all for that feed or my related ones if someone waits a day or three to hear an update. The Cache-Control (and Retry-After) headers are set to many hours to steer polls to the middle of the day, and skipHours is set to request avoid polling my off-grid powered server overnight in part since I only update feeds during the day.

@Frenzie

Frenzie commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

It's 48 hours.

Edit: cross-ref to logs regarding the above: #8928 (comment)

    [25/Oct/2026:06:33:24 +0000] "GET /rss/note-on-site-technicals.rss HTTP/2.0" 429 544 "-" "FreshRSS/1.30.0 (Linux; https://freshrss.org)"
    [25/Oct/2026:06:33:24 +0000] "GET /rss/podcast.rss HTTP/2.0" 429 544 "-" "FreshRSS/1.30.0 (Linux; https://freshrss.org)"
    [25/Oct/2026:07:03:19 +0000] "GET /rss/note-on-site-technicals.rss HTTP/2.0" 429 544 "-" "FreshRSS/1.30.0 (Linux; https://freshrss.org)"
    [25/Oct/2026:07:03:19 +0000] "GET /rss/podcast.rss HTTP/2.0" 429 544 "-" "FreshRSS/1.30.0 (Linux; https://freshrss.org)"
    [25/Oct/2026:07:35:35 +0000] "GET /rss/note-on-site-technicals.rss HTTP/2.0" 429 544 "-" "FreshRSS/1.30.0 (Linux; https://freshrss.org)"
    [25/Oct/2026:07:35:35 +0000] "GET /rss/podcast.rss HTTP/2.0" 429 544 "-" "FreshRSS/1.30.0 (Linux; https://freshrss.org)"

Edit 2:

I think the timing looks suspiciously much like the fallback value (which sounds a tad low, but that aside):

		# Default rate limit duration (in seconds), when HTTP response header `Retry-After` is absent.
		'retry_after_default' => 1500,
		# Maximal rate limit duration (in seconds), overriding HTTP response header `Retry-After`.
		'retry_after_max' => 172800,

/**
* Store the HTTP Retry-After header value of an HTTP `429 Too Many Requests` or `503 Service Unavailable` response.
*/
public static function setRetryAfter(string $url, string $proxy, string $retryAfter): int {
$txt = self::getRetryAfterFile($url, $proxy);
if ($txt === '') {
return 0;
}
$limits = FreshRSS_Context::systemConf()->limits;
if (ctype_digit($retryAfter)) {
$retryAfter = time() + (int)$retryAfter;
} else {
$retryAfter = \SimplePie\Misc::parse_date($retryAfter) ?:
(time() + max(600, $limits['retry_after_default'] ?? 0));
}
$retryAfter = min($retryAfter, time() + max(3600, $limits['retry_after_max'] ?? 0));
@mkdir(self::RETRY_AFTER_PATH);
if (!touch($txt, $retryAfter)) {
Minz_Log::error('Failed to set Retry-After for ' . $url);
return 0;
}
return $retryAfter;
}

@Frenzie

Frenzie commented Oct 25, 2026

Copy link
Copy Markdown
Member

Could you share the actual Retry-After header if you run the request yourself with curl?

@DamonHD

DamonHD commented Oct 25, 2026 •

Copy link
Copy Markdown

It varies to try to steer towards early afternoon, but in case you can read Apache config:

# Set RSS feed cache time, ie minimum poll interval.
# Give podcast RSS and similar feeds longer expiry out of work hours.
# Usually have any Retry-After match what the cache time would have been.
<If "%{TIME_HOUR} -lt 8 || %{TIME_HOUR} -gt 21">
    # In skipHours.
    # Long enough to jump out of skipHours in one go.
    ExpiresByType application/rss+xml "access plus 10 hours 7 minutes"
    Header always set Retry-After "36420" env=REDIRECT_RSS_RATE_LIMIT
    # Reduce Atom feed processing at night too.
    ExpiresByType application/atom+xml "access plus 10 hours 7 minutes"
</If>
<ElseIf "%{TIME_HOUR} -lt 12">
    # Coming up to the open hour at 12XXZ.
    # Normal general expiry time of ~4h (>>1h).
    # But try to push bad bots getting 429/503 to the noon 'open' slot.
    ExpiresByType application/rss+xml "access plus 4 hours 7 minutes"
    Header always set Retry-After "3420" env=REDIRECT_RSS_RATE_LIMIT
</ElseIf>
<ElseIf "%{TIME_HOUR} -gt 17">
    # Coming up to the start of skipHours.
    # Jump expiry right over coming skipHours block.
    ExpiresByType application/rss+xml "access plus 14 hours 7 minutes"
    Header always set Retry-After "50620" env=REDIRECT_RSS_RATE_LIMIT
</ElseIf>
#<ElseIf "-f '/run/EXTERNAL_BATTERY_LOW.flag'">
<ElseIf "%{TIME_MON} -lt 3 || %{TIME_MON} -gt 10">
    # Winter: defer next poll just under 1d: drift back to early afternoon.
    ExpiresByType application/rss+xml "access plus 23 hours 57 minutes"
    Header always set Retry-After "86220" env=REDIRECT_RSS_RATE_LIMIT
</ElseIf>
<Else>
    # Default expiry time of ~4h for podcast RSS and similar feeds.
    ExpiresByType application/rss+xml "access plus 4 hours 7 minutes"
    Header always set Retry-After "14720" env=REDIRECT_RSS_RATE_LIMIT
</Else>

A client will only get 429s and Retry-After if polling too fast. But also note the expiry (Cache-Control) alongside set for 200s.

See my WIP grumble on this entire topic! https://www.earth.org.uk/RSS-efficiency.html

Thank you!

@DamonHD

DamonHD commented Oct 25, 2026 •

Copy link
Copy Markdown

Here is the response header set that this client will currently be seeing, which is the shortest Retry-After available on this feed!

  HTTP/1.1 429 Too Many Requests
  Date: Sun, 25 Oct 2026 10:35:27 GMT
  Server: Apache
  Retry-After: 3420
  Vary: Accept-Encoding,Referer
  Upgrade: h2
  Connection: Upgrade, close
  Last-Modified: Wed, 04 Mar 2026 10:09:21 GMT
  Accept-Ranges: bytes
  Content-Length: 564
  X-Frame-Options: DENY
  Content-Type: text/html
  Content-Encoding: gzip

@Frenzie

Frenzie commented Oct 25, 2026

Copy link
Copy Markdown
Member

In normal conditions that would work. I'd venture they either purposefully changed something or their cache is somehow broken due to incorrect permissions. It does look like there was a bug in 1.30.0 (#9390) but that was about domain-wide retry-after.

The first thing it does when encountering a retry-after in the cache is this:

// Retry-After is stored for the URL as requested, not as stored for the feed
if (($retryAfter = FreshRSS_http_Util::getRetryAfter($url, $this->proxyParam())) > 0) {
throw new FreshRSS_Feed_Exception('For that domain, will first retry after ' . date('c', $retryAfter) .
'. ' . $this->url(includeCredentials: false), code: 503);
}

Which shows up in the logs as follows:

For that domain, will first retry after 2026-10-25T13:32:11+00:00. https://clint.id.au/?feed=rss2

Afaict from some quick tests that all works as it should. I.e., if you say 2 hours (7200) it won't retry for 2 hours, and so on.

I'll glance around a bit more though.

Frenzie added a commit to Frenzie/FreshRSS that referenced this pull request Oct 25, 2026
Because of FreshRSS#8029 and FreshRSS#8218, a proxy would never apply Retry-After.

Possibly related to the problem described in <FreshRSS#7760 (comment)> by @DamonHD.
@Frenzie Frenzie mentioned this pull request Oct 25, 2026
3 of 4 tasks
Alkarex added a commit that referenced this pull request Oct 26, 2026
* Fix Retry-After cache when proxy is used

Because of #8029 and #8218, a proxy would never apply Retry-After.

Possibly related to the problem described in <#7760 (comment)> by @DamonHD.

* work around line length 168 instead of 165

* Update app/Models/Feed.php

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
@DamonHD

DamonHD commented Oct 27, 2026 •

Copy link
Copy Markdown

Edit 2:

I think the timing looks suspiciously much like the fallback value (which sounds a tad low, but that aside):

		# Default rate limit duration (in seconds), when HTTP response header `Retry-After` is absent.
		'retry_after_default' => 1500,
		# Maximal rate limit duration (in seconds), overriding HTTP response header `Retry-After`.
		'retry_after_max' => 172800,

A thought: maybe maybe maybe you could do the planet one tiny extra favour here and push that default/fallback up to 2h? If things are a bit broken, fail slower and use less CPU/bandwidth/carbon?

Anyhow, thanks for taking this seriously!

@Frenzie

Frenzie commented Oct 27, 2026

Copy link
Copy Markdown
Member

I don't know the precise rationale behind the default. @marienfressinaud or @Alkarex probably does.

@marienfressinaud

Copy link
Copy Markdown
Member

I'm pretty sure I've never worked on this part, so I won't be of any help here :)

@Frenzie

Frenzie commented Oct 27, 2026

Copy link
Copy Markdown
Member

I think it's just the "Do not automatically refresh more often than" default; I meant in that regard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RSS standard the standard is defined f.e. on https://www.rssboard.org SimplePie 🍰

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement support for HTTP header Retry-After (429, 503) [Bug] Openrss blocking freshrss for too many simultaneous requests

4 participants