Users who open too many Discourse pages in tabs get rate limited

I see it regularly when I open tabs in the background too quickly, but it took me 15 minutes to figure out why I was getting rate limited after opening a huge number of them slowly and forgetting about them for a while.

I asked Claude to look at it and it said:

…normally a hidden tab polls once a minute, so 80 tabs is well under the limits. Once something bunches the polls together and one gets a 429, each tab retries every 15 seconds, four times faster than normal. 80 tabs retrying every 15 seconds is about 53 requests per 10 seconds, over the limit of 50. Discourse also counts the rejected requests, so the count never drops. Above about 75 tabs it keeps itself going until tabs are closed.

As soon as I rebooted the server, every browser tab apparently reconnected at the same time.

Claude said that

Hidden tabs poll 4 times faster after a 429, which can lock a user out of the site.

After a poll gets a 429, message-bus.js waits max(Retry-After, 15 s) before polling again, even in a hidden tab (the rateLimited branch of the complete handler). A hidden tab normally polls every backgroundCallbackInterval, which is 60 s in Discourse, so a 429 makes background tabs poll four times as often as when things are fine. With many tabs open, those retries alone keep the user over Discourse’s per-user limit (max_reqs_per_ip_per_minute, 200 by default): four polls a minute per tab passes 200 at about 50 tabs. The limiter is created with aggressive: true, so rejected requests count too and the block never expires. Every page load gets “Slow down, you’re making too many requests” until the user closes tabs. Changing network doesn’t help, because the limit is per user.

The cross-tab brake (hiddenTabShouldWait, a 1.5 s spacing through localStorage) also didn’t space hidden tabs out.

Suggested fix: when rate limited, wait max(Retry-After, normal interval for this tab), where the normal interval is callbackInterval when long polling and backgroundCallbackInterval otherwise. Add random jitter so tabs rejected together don’t retry together, and ideally back off on repeated 429s. Visible tabs are unchanged, since their interval is shorter than any Retry-After.

I don’t know how prevalent the problem is, but it might be worth looking at.

1 Like