Closed switchupcb closed 1 year ago
The test originally failed due to an issue with the actual test. Once that was fixed, the issue is a data race occurring when one Session is writing to the *Client
struct (e.g., bot.ApplicationID = ready.Application.ID
) while another Session is performing a read operation (e.g., LogCommand
).
So I must investigate the best way to handle this data race or declare it benign: It is most likely solved through heavy usage of an RWMutex
.
Here is a solution to the issue above.
First, a quick recap on data race semantics within the disgo.*Client
.
disgo
and is set by the user at initialization.So these structs and their respective operations have sufficient data race protection.
The main issue with bot.ApplicationID
is that it is referenced over 600 times.
However, the field is only written to three times in the entire repository (including examples):
// from ./_examples/bot/main.go L#79 demonstrating that the field exists.
bot.ApplicationID = ""
// from ./wrapper/tests/integration/coverage_test.go L#57 setting the application ID for subsequent requests.
bot.ApplicationID = app.ID
// OFFENDING LINE: from ./wrapper/session.go L#327 setting the application ID for logging purposes.
bot.ApplicationID = app.ID
This situation leaves the following questions:
It is required for certain requests. So the user must have a way to store the application ID in the client.
There are a few options available:
For two writes? No.
A user (developer) is expected to set the application ID before the application is running. Especially when the user is using an operation that — they know — requires an application ID.
The only operations that require an application ID are certain requests. In other words, APPLICATION ID IS NOT USED IN SESSION LOGIC (except for logging purposes): The main reason that it's included is in the rare case that the user decides to run two applications within the same codebase.
A user is only expected to run a single bot within a single time, even though running multiple bots is supported by disgo
. So the real question: Does the application ID of the bot need to be set in the session code (when the ready event is received)?
So remove the offending write.
This pull request implements #26 with the following changes:
*Tests for the Gateway Rate Limits were added in the commit 'add Gateway tests`:
TestGatewayGlobalRateLimit
in/wrapper/tests/integration/ratelimit_test.go
: Sends 121 events using the Gateway rate limit.TestGatewayIdentifyRateLimit
in/wrapper/tests/integration/ratelimit_test.go
: Connects two sessions to the Gateway in a manner that tests the Identify Rate Limit.However,
TestGatewayGlobalRateLimit
has been removed in commit 'remove TestGatewayGlobalRateLimit test' for the following reason: