discordgo icon indicating copy to clipboard operation
discordgo copied to clipboard

Rate limit unmarchal error

Open kubastick opened this issue 5 years ago • 12 comments

After few weeks of running our bots without issues, we encountered this issue which caused us to be rate-limited by cloudflare:

[DG0] restapi.go:149:RequestWithLockedBucket() rate limit unmarchal error, invalid character '<' looking for beginning of value

kubastick avatar Jun 10 '19 19:06 kubastick

@kubastick have you gotten more of these?

From that bit of error information, it looks like somehow you got malformed json which could be a discord bug, cloudflare bug, a network issue, etc..

Just wondering if this is a consistently reoccurring issue or a one off glitch?

bwmarrin avatar Jul 30 '19 22:07 bwmarrin

This has just started happening to me. Even worse, it only seems to happen when I run it off of my main server, it doesn't happen when i run it off my desktop, which means it's likely some sort of cloudflare bug that's happening on a per-ip basis.

I was trying to extract the exact value being passed to the response (since a < looked suspiciously like an HTML page being served by a broken cloudflare endpoint) but the issue vanished right after I recompiled with additional debugging enabled. If I catch the issue again I will try to dump the exact HTML being returned, but this seems like it could be a recurring bug either by discord or cloudflare.

ErikMcClure avatar Aug 18 '19 02:08 ErikMcClure

FYI, I'm carrying a patch to treat these as a 2500ms ratelimit delay.

riking avatar Nov 17 '19 06:11 riking

@bwmarrin I started seeing these once I hit global rate limits. Prior to them I did not see any issues.

mistahj67 avatar Nov 21 '19 20:11 mistahj67

Whenever cloudflare blows up, discordgo starts getting HTML responses from cloudflare for all requests, which looks like this:

Failed to send message:  HTTP 400 Bad Request, <html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>cloudflare</center>
</body>
</html>

This means every single part of the API starts returning invalid JSON and blows up all sorts of stuff. This is where the bug mentioned here comes from, and can be the cause of any related bugs.

ErikMcClure avatar Mar 09 '20 17:03 ErikMcClure

Just making note that this issue is still around. This time it doesn't look like it received an HTML response, as the response begins with 'e':

[DG0] restapi.go:154:RequestWithLockedBucket() rate limit unmarshal error, invalid character 'e' looking for beginning of value

un4gi avatar Dec 08 '22 09:12 un4gi

Just making note that this issue is still around. This time it doesn't look like it received an HTML response, as the response begins with 'e':

[DG0] restapi.go:154:RequestWithLockedBucket() rate limit unmarshal error, invalid character 'e' looking for beginning of value

I'm getting this same error message, very consistently, even when I shouldn't be ratelimited

DeathHound6 avatar Dec 20 '22 13:12 DeathHound6

@un4gi and @DeathHound6

Can you enable debugging and log the packets so we can see what you're actually getting so we know what the issue is? That way we know if it's a valid response from Discord, something from cloudflare, or something else entirely.

If you set the Debug flag on the session to true it will print out the packets, hopefully :)

bwmarrin avatar Dec 20 '22 21:12 bwmarrin

@bwmarrin Mine's ratelimited again (I realised after my last post that I'm on a shared host so it's likely others ratelimiting me)

With the debug flag set to true, the response body from the gateway endpoint is simply error code 1015. My guess is the library is trying to parse this as being JSON, which it obviously isn't, but this is just a guess

DeathHound6 avatar Dec 23 '22 12:12 DeathHound6

Finally getting ratelimited again. Here is the whole debug error, with token and other sensitive info removed

2023/01/05 17:16:23 API REQUEST      GET :: https://discord.com/api/v9/gateway
2023/01/05 17:16:23 API REQUEST  PAYLOAD :: []
2023/01/05 17:16:23 API REQUEST   HEADER :: [Authorization] = [Bot token_here]
2023/01/05 17:16:23 API REQUEST   HEADER :: [User-Agent] = [DiscordBot (https://github.com/bwmarrin/discordgo, v0.26.1)]
2023/01/05 17:16:23 API RESPONSE  STATUS :: 429 Too Many Requests
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Cache-Control] = [private, max-age=0, no-store, no-cache, must-revalidate, post-check=0, pre-check=0]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Strict-Transport-Security] = [max-age=31536000; includeSubDomains; preload]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Date] = [Thu, 05 Jan 2023 17:16:23 GMT]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [X-Frame-Options] = [SAMEORIGIN]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Report-To] = [{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=awtGyUArLaeK8G5mA34LIATTlAeu9fzX%2FXRZWVPPgFCgA8%2BJTSVwqbGjZlgkOc5c0QFg2QyTP4WZZRnltHlU3qBx62meK%2FTM4Tba6cyERZ8AIwFZiFPWTQuUTqc4"}],"group":"cf-nel","max_age":604800}]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [X-Content-Type-Options] = [nosniff]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Server] = [cloudflare]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Cf-Ray] = [784ddc88ca2c61aa-ORD]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Retry-After] = [80355]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Nel] = [{"success_fraction":0,"report_to":"cf-nel","max_age":604800}]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Vary] = [Accept-Encoding]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Alt-Svc] = [h3=":443"; ma=86400, h3-29=":443"; ma=86400]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Content-Type] = [text/plain; charset=UTF-8]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Referrer-Policy] = [same-origin]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Expires] = [Thu, 01 Jan 1970 00:00:01 GMT]
2023/01/05 17:16:23 API RESPONSE  HEADER :: [Content-Length] = [16]
2023/01/05 17:16:23 API RESPONSE    BODY :: [error code: 1015]


2023/01/05 17:16:23 [DG0] restapi.go:205:RequestWithLockedBucket() rate limit unmarshal error, invalid character 'e' looking for beginning of value
panic: invalid character 'e' looking for beginning of value

The error traceback of this error also originates from session.Open()

DeathHound6 avatar Jan 05 '23 17:01 DeathHound6

I'm getting rate limited as well but only on one single command, any update on this?

For me it only happens when using webhook edit function.

griffinmc22 avatar Apr 02 '23 01:04 griffinmc22

Again, any update on this? I'm also encountering these errors a lot.

MayoGuy avatar Oct 22 '23 05:10 MayoGuy