Skip to content
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

Rate limit unmarchal error #659

Open
kubastick opened this issue Jun 10, 2019 · 12 comments
Open

Rate limit unmarchal error #659

kubastick opened this issue Jun 10, 2019 · 12 comments

Comments

@kubastick
Copy link

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
@bwmarrin
Copy link
Owner

@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?

@ErikMcClure
Copy link

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.

@riking
Copy link

riking commented Nov 17, 2019

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

@mistahj67
Copy link
Contributor

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

@ErikMcClure
Copy link

ErikMcClure commented Mar 9, 2020

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.

@un4gi
Copy link

un4gi commented Dec 8, 2022

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

@DeathHound6
Copy link

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

@bwmarrin
Copy link
Owner

@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 :)

@DeathHound6
Copy link

DeathHound6 commented Dec 23, 2022

@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
Copy link

DeathHound6 commented Jan 5, 2023

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()

@griffinmc22
Copy link

griffinmc22 commented Apr 2, 2023

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.

@MayoGuy
Copy link

MayoGuy commented Oct 22, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants