Skip to content

Rest client ratelimit inconsistencies #1909

@VelvetToroyashi

Description

@VelvetToroyashi

Initially to be a comment in #1908, I wanted to point out some issues with this:

https://github.com/DSharpPlus/DSharpPlus/blob/4f42a502059f6b1c5f155c8ef9622f422f9c2bcf/DSharpPlus/Net/Rest/RestClientOptions.cs

Namely in regards to the data passed to rest client;

First, Timeout is a TimeSpan, which is good, and sensible.

public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(10);

However, the retry delay fallback is a double, and represents seconds.

/// <summary>
/// Specifies the delay to use when there was no delay information passed to the rest client. Defaults to 2.5 seconds.
/// </summary>
public double RatelimitRetryDelayFallback { get; set; } = 2.5;

This would be OK if the first were also a double, and/or measured in seconds, however this timeout is an int, and measured in milliseconds.

/// <summary>
/// Specifies the amount of milliseconds we should be waiting for a ratelimit bucket hash to initialize.
/// </summary>
public int InitialRequestTimeout { get; set; } = 200;

This is undoubtedly a confusing mess to deal with and relies on looking closely at documentation to not accidentally set nonsensical values in either direction for users that want to fine-tune the library.

Ideally, this would be consistent, and all three would be TimeSpan, which is an unambiguous datatype,


public int MaximumRatelimitRetries { get; set; } = int.MaxValue;

I also had concerns about this; it's an int, so I'd expect that -1 would be used as the sentinel value, however int.MaxValue is so absurdly huge that this doesn't really matter. That being said, perhaps this could be set to uint for that very reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    coreratelimitsIssues about ratelimiting errors or misbehaving limits

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions