Skip to content

[Bug]: Interaction responses being ratelimited #2618

@CrisFeo

Description

@CrisFeo

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

I'm seeing preemptive rate limits occur on button interaction responses when we have a lot of users hitting buttons. As per Discord docs interactions should be rate limited separately from one another however we are seeing logs that indicate they are sharing a bucket hash.

I've done some digging here and it looks like the CreateInteractionResponse method is passing an empty set of ids via new BucketIds(): https://github.com/discord-net/Discord.Net/blob/3.9.0/src/Discord.Net.Rest/DiscordRestApiClient.cs#L1383

Digging into the underlying rate limit code I've found that dnet generates a BucketId keyed to the calling method (CreateInteractionResponse here) and "customizes" (for lack of a better term) it using the passed BucketIds:
https://github.com/discord-net/Discord.Net/blob/3.9.0/src/Discord.Net.Rest/DiscordRestApiClient.cs#L2389

My read on this logic (after tracing it through the queuing system) is that it will result in every call to CreateInteractionResponse using the same bucket for preemptive rate limiting purposes (Instead of what seems to be intent: apply no bucketed rate limiting).

This idea is supported by the implementation for webhooks (which interactions are closely related to) which does pass the webhook id via ids: https://github.com/discord-net/Discord.Net/blob/3.9.0/src/Discord.Net.Rest/DiscordRestApiClient.cs#L843

I'm not sure what the ultimate solution would look like as ideally interaction calls should ignore global rate limit too. However a passable one could involve simply passing interactionId in ids for interaction endpoints to create a separate rate limit bucket for each interaction ala webhooks.

Version

3.9.0

Working Version

No response

Logs

Preemptive Rate limit triggered: POST interactions/1080898005743439953/aW50ZXJhY3Rpb246MTA4MDg5ODAwNTc0MzQzOTk1MzoxU3ZtempTT1pDcGhXbXJldDJqQTEwd3pLdFlIRGdoZmVoUWlYb3FNWVN1OGVJUG5ITklndHliVlp2TFp6VE1ncEhhdmQ1QmlxQXdPTERCaVNvV25SZERESk1LVTZ4bEt3Y2FROU93M2s5YTk3cWNVZ3hxeFlVZ3p4THpqZ2V3Vw/callback (Bucket: 432f6223265d156004ac81366c5a948f)
Preemptive Rate limit triggered: POST interactions/1080898002299932673/aW50ZXJhY3Rpb246MTA4MDg5ODAwMjI5OTkzMjY3MzpPbEpPamM2Z0JkM2hyRk45VWJBdWJGVklkR0hvdmx4NmVmUDNIcWJ1NzFScWg4a3Q1ZFVlS1NIV1c0aFExMzFSQWZXWDhNNHlSZlJ0bmZvRHBFbFp4WUJ0UGpNckRZVmR3VHBiTGYxTE1jS0ZpeGQ3d3Zkc2I2TmRJZk5NT08xVg/callback (Bucket: 432f6223265d156004ac81366c5a948f)
... A lot more of this ...

Sample

No response

Packages

None

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions