-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for rate limit detection / retries @ linkcheck #7388
Comments
+1; Reasonable. I'm not familiar with rate-limit detection. But it would be helpful. |
I implemented similar logic here for reference: jupyterlab/pytest-check-links#7 |
This may need to be revisited once Sphinx implements sphinx-doc/sphinx#7388
See also #6629. |
Should be solved by #8467. |
Follow the Retry-After header if present, otherwise use an exponential back-off. Close sphinx-doc#7388
@francoisfreitag Could I close this? |
I think so, even if the issue asks for more configuration that has been made available in #8467. Let’s start with the simple solution first. We can consider more advanced configuration if it is not sufficient. Perhaps using an event as suggested in #8467 (comment). |
Honestly, I'd prefer the backoff lib to be integrated and the callbacks for determining whether the retry is necessary to be exposed... |
@webknjaz Please let me know why do you want callbacks (flexibility)? Do you have any troublesome links? I still don't understand why you need such a feature. |
I think that it's a good idea for Sphinx to implement support for some common standardized headers. But OTOH there's plenty of services reinventing the wheel, using something beyond the standard, providing more context with extra headers like GitHub does (https://docs.github.com/en/free-pro-team@latest/rest/overview/resources-in-the-rest-api#rate-limiting) or not playing by the rules, basically lying about when to retry. This is why I'm convinced that there should be an interface for providing a more flexibile configuration. Having Sphinx core special-case each and every possible unconventional case is not a sustainable solution while empowering users to deal with this is. I can't provide any URLs at the moment, I guess, GHA badges had problems at some point so I added them to the ignore list, I'll need to re-check my ignores across projects to see if there's anything interesting among those. I vaguely recall something about codecov returning 4xx code w/o any extra metadata but I can't confirm this right now. |
Thanks for documenting why the additional complexity might be worth it. Some web servers definitely misbehave. The GitHub API rate limits is probably not a realistic example, I doubt people do GitHub API calls in their documentation. An example noticed during the development of the current version was GitHub web returning Currrent situationGoodI hope the majority of cases. Most web servers won’t rate-limit, or specify a correct SuboptimalThese cases should eventually work:
Poor
ImprovementsGiving user control allows them to improve the wait time by specifying the optimal delay, or reading a part of the response to know when to retry. It also allows overriding a lying web server. Definitely, both are improvements over the current situation.
I agree.
I find acceptable that I’m concerned that only a small number of users would be willing to take the time to observe misbehaving web servers (either to figure out where the rate limits are specified or observe the wait time experimentally) and write a retry policy for it. Delegating control to users increases complexity:
Possible implementationTo anyone interested in attempting an implementation, an earlier version of the patch was offering a Going furtherPerhaps not only rate limits need to be configurable, but users would want to inspect all responses and decide what to do (consider the link working, broken, redirected, rate-limited, etc). |
In short, my opinion is to wait for a couple releases, see if the current implementation solves most issues. Once remaining problematic behaviors are clearly identified, decide on the best course of action. Perhaps add events, allowing users to have complete control over a link validity and behavior on rate limits (and other kind of errors). |
@francoisfreitag this is not related to rate-limits but here's one case when allowing to amend the validity detection mechanism would help. I've added a link to https://github.com/python/cpython/blob/c39b52f/Lib/poplib.py#L297-L302 and now I get: broken link: python/cpython@c39b52f/Lib/poplib.py#L297-L302 (Anchor 'L297-L302' not found) When you look at the source, it becomes obvious that there are anchors for Ref: https://github.com/cherrypy/cheroot/runs/1511163391?check_suite_focus=true#step:9:603 |
In an ideal world, Realistically, |
Sounds fair. |
Did you mean to link some other issue? You linked this one. |
It seems there is no remaining tasks for this issue. Can I close this? |
This issue has turned to be about control over the retry policy (or even linkcheck behavior in general) for power users. Delegating control increases complexity, both in user configuration and on Sphinx side. My preferred way forward is to close this issue. I suggest opening a new issue when limitations of the current implementation cause an actual problem. That would help narrowing the space of possible issues and focusing the discussion. |
Thank you for your comment. Let's close this :-) |
We explicitly ignore checking anchors for line-range anchors on GitHub which are dynamically generated and, otherwise, show up as broken links. See sphinx-doc/sphinx#7388 (comment). We also ignore links to resources that require authentication.
Is your feature request related to a problem? Please describe.
When there's a lot of references to GitHub issues and Pull Requests, linkcheck goes over them quite quickly and at some point, sometimes, it hits their rate limit.
Describe the solution you'd like
linkcheck needs some sort of a setting for rate-limiting (leaky bucket?) and retries (exponential backoff?). These settings could be per-domain similar to #7247 (comment) for flexibility.
Also, maybe there could be another setting for a callable supplied by users. This'd allow inspecting the response and returning
True
/False
from such a callback specifying if the failure is temporary and the request should be retried later (similar togiveup
callback in https://pypi.org/p/backoff/ library — maybe it could even be integrated?).Describe alternatives you've considered
N/A
Additional context
Basically, this fails in CI:
(https://zuul.vexxhost.dev/t/cherrypy/build/e02b806392eb41c7a4030ec4bae735c3/console)
The text was updated successfully, but these errors were encountered: