Page MenuHomePhabricator

Regression: Reading spam blacklists of all projects suddenly returns status 429 on fifth consecutive read
Closed, ResolvedPublicBUG REPORT

Description

I am working on functionality for https://spamcheck.toolforge.org and for that I need to read the raw spam blacklists of all projects on program startup. This used to work fine last week, even with parallel requests, but now it is suddenly severely limited.

Testing reveals that only throttling to one request per second would help. This would mean that program startup would take 15+ minutes while before it took less than 5 seconds.

Tested at home and on dev.toolforge.org.

Steps to replicate the issue (include links if applicable):

Run this bash script

urls=(
  "https://nl.wikipedia.org"
  "https://nl.wiktionary.org"
  "https://nl.wikibooks.org"
  "https://nl.wikinews.org"
  "https://nl.wikiquote.org"
  "https://nl.wikisource.org"
  "https://nl.wikivoyage.org"
  "https://nn.wikipedia.org"
)

user_agent="reqtest-phab-T369414"

for url in "${urls[@]}"; do
  full_url="$url/wiki/MediaWiki:Spam-blacklist?action=raw"
  status_code=$(curl -o /dev/null -s -w "%{http_code}\n" -A "$user_agent" "$full_url")
  echo "Status code for $full_url: $status_code"
done

What happens?:
Output:

Status code for https://nl.wikipedia.org/wiki/MediaWiki:Spam-blacklist?action=raw: 200
Status code for https://nl.wiktionary.org/wiki/MediaWiki:Spam-blacklist?action=raw: 200
Status code for https://nl.wikibooks.org/wiki/MediaWiki:Spam-blacklist?action=raw: 200
Status code for https://nl.wikinews.org/wiki/MediaWiki:Spam-blacklist?action=raw: 404
Status code for https://nl.wikiquote.org/wiki/MediaWiki:Spam-blacklist?action=raw: 200
Status code for https://nl.wikisource.org/wiki/MediaWiki:Spam-blacklist?action=raw: 429
Status code for https://nl.wikivoyage.org/wiki/MediaWiki:Spam-blacklist?action=raw: 429
Status code for https://nn.wikipedia.org/wiki/MediaWiki:Spam-blacklist?action=raw: 429

What should have happened instead?:
HTTP status 429 (too many requests) should not happen for consecutive requests.

Event Timeline

I haven't checked if this applies to _all_ action=raw requests.

Using the Mediawiki REST API works good enough. So this is not that urgent for me anymore.

when using curl, please specify a custom user agent.

when using curl, please specify a custom user agent.

I do in my code, the snippet is only for demonstration. In my code it is sblwatch/0.0.1 (User:Count Count). I will update the snippet to user some user agent.

I expect that the ?action=raw query string is what is causing you to run into a rate limit. I think you will have a better and more consistent time if you fetch the page content via the Action API instead:

T369414-rate-limit.sh
#!/usr/bin/env bash
urls=(
  "https://nl.wikipedia.org"
  "https://nl.wiktionary.org"
  "https://nl.wikibooks.org"
  "https://nl.wikinews.org"
  "https://nl.wikiquote.org"
  "https://nl.wikisource.org"
  "https://nl.wikivoyage.org"
  "https://nn.wikipedia.org"
)

user_agent="reqtest-phab-T369414-bd808"

for url in "${urls[@]}"; do
  full_url="$url/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1"
  status_code=$(curl -o /dev/null -s -w "%{http_code}\n" -A "$user_agent" "$full_url")
  echo "Status code for $full_url: $status_code"
done
$ ssh dev.toolforge.org
$ time ./T369414-rate-limit.sh
Status code for https://nl.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nl.wiktionary.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nl.wikibooks.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nl.wikinews.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nl.wikiquote.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nl.wikisource.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nl.wikivoyage.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200
Status code for https://nn.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1: 200

real    0m1.005s
user    0m0.462s
sys     0m0.123s

The data you want can be extracted from the query.pages[0].revisions[0].slots.main.content element of the response:

$ curl -s -A reqtest-phab-T369414-bd808 'https://nl.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&rvslots=main&rvlimit=1&rvcontentformat-main=text/x-wiki&titles=MediaWiki:Spam-blacklist&format=json&formatversion=2&utf8=1' | jq --raw-output .query.pages[0].revisions[0].slots.main.content
 #################################################################
 # Documentatie: http://www.mediawiki.org/wiki/Extension:SpamBlacklist
 #
 # Je kunt hier met behulp van reguliere expressies webadressen opgeven die spam zijn en dus het gebruik ervan voorkomen.
 # Deze lijst heeft alleen invloed op de lokale wiki, om de globale lijst te zien [[:mw:Spam blacklist|klik hier]].
 # Zie documentatie op de [[mw:Extension:SpamBlacklist|MediaWiki]]
 # Gebruik [[:mw:Manual:BlockedExternalDomains|BlockedExternalDomains]] voor eenvoudige adressen: '''[[Speciaal:BlockedExternalDomains|BlockedExternalDomains]]'''.
 #
 # De syntaxis voor het gebruik is:
 # Je moet \ voor een punt gebruiken, en aan het begin en einde van het adres moet je \b plaatsen.
 # Om een commentaar te plaatsen, gebruik je '#' en een spatie ervoor.
 # Controleer voordat je een site toevoegt of deze al in de lijst staat.
 #
 # Verzoeken tot opname in deze lijst kunnen worden geplaatst op
 # [[Wikipedia:Verzoekpagina voor moderatoren/Spam-blacklist]].
 #
 # Plaats bij het toevoegen van een url:
 #   * Je naam
 #   * De reden voor het toevoegen
 #   * Datum
 #   * Oldid, wanneer het een verzoek is op [[Wikipedia:Verzoekpagina voor moderatoren/Spam-blacklist]]
 #            Het verzoek kan dan bekeken worden via
 #            http://nl.wikipedia.org/w/index.php
 #            ?title=Wikipedia:Verzoekpagina_voor_moderatoren/Spam-blacklist
 #            &oldid=<nummer>
 #################################################################
<!-- leave this line exactly as it is --> <pre>

# 10-12-2007, na jarenlange linkspampogingen nu op deze lijst opgenomen
\bwettelijkerente\.(?:info|org|nl|net)\b

# toegevoegd door RonaldB
# 11-12-2007 linkspam door meerdere IP's
# videospam op Filip de Winter en Gerolf Annemans
\/videoplay\?docid=-4198910042830580654
\/videoplay\?docid=-7922346519436353196
\bshoturl\.us\/081
\bshoturl\.us\/5M1

#toegevoegd door MoiraMoira
#21-12-2008 doorgaand linkspam op artikel Tangram
\bmallorcaweb\.net/tangrampeces

#19-01-11 linkspam naar via cx-domein doorgeleide Turkse site, ongeschikt voor global blacklist maar op nl:wiki niet gebruikt
\.tr\.cx\b

# Zie http://nl.wikipedia.org/w/index.php?title=Wikipedia:Verzoekpagina_voor_moderatoren/Spam-blacklist&oldid=27623430#Nieuwe_verzoeken
#volgende vervangt twee bovenstaande en mogelijke andere varianten (door RonaldB)
-verzekeringvergelijke.\..{2,3}\b

# XXBlackburnXx - Herhaalde linkspam op enwiki en hier - 7-10-2023
\bbestcmstrategies\.

# Gokspammers
\bstmbet                    # XXBlackburnXx 07-10-2023
moneygame(?:s|77)           # XXBlackburnXx 20-11-2023
\.ac\.id/(?:store|shop)/    # XXBlackburnXx 22-11-2023
\bhei89\w*\.                # XXBlackburnXx 22-11-2023
\bmgm88\.                   # XXBlackburnXx 01-12-2023
slot777                     # XXBlackburnXx 26-02-2024
vin777                      # XXBlackburnXx 01-03-2024
space-*andromeda            # XXBlackburnXx 25-05-2024

chatgpt # herhaalde linkspam. Officieel domein is openai.com - XXBlackburnXx 16-12-2023
\byoutube\.com/@Oscareduardo1012 # Cross-wiki zelfpromotie - XXBlackburnXx 28-12-2023
\bjouwweb\.site\b # Uitbreiding op de al geblokkeerde website jouwweb.nl - XXBlackburnXx 13-03-2024

</pre>

@bd808 Thank you! I have started using the Mediawiki REST API instead (see https://phabricator.wikimedia.org/T369414#9958156), using e.g. https://en.wikipedia.org/w/rest.php/v1/page/MediaWiki:Spam-blacklist, which works fine as well.

So IMHO this task can be closed, not sure if I should do that myself.

Dzahn claimed this task.
Dzahn subscribed.

Being bold and closing the task because the task creator said so. Please feel free to reopen if you disagree.

Dzahn removed Dzahn as the assignee of this task.Jul 10 2024, 5:26 PM