* Gateway: Fix gateway reconnect
This commit uses the correct timeout, Gateway.ReconnectTimeout, when reconnecting. Furthermore, it adds a delay between consecutive, failed reconnects.
* Gateway: Stop pacemaker when calling Gateway.CloseGracefully
* API: remove unnecessary leading/trailing whitespaces
* Gateway: Add Gateway.OnScalingRequired callback
* Gateway: Make all user initiated user closures graceful and ensure that closures are respected during reconnects
* Gateway: Fix typo
* Gateway: Add Gateway.ReconnectAttempts and deprecate .ReconnectTimeout
* Gateway: Add Gateway.Pause and reexport .Reconnect and .ReconnectCtx
* Gateway: Improve the Gateway.OnShardingRequired docs
* Wsutil: Code cleanup
* gateway: add the possibility of graceful closure
* wsutil: rename ConnGracefulCloser to GracefulCloser
* Gateway: rename Gateway.CloseSession to .CloseGracefully
This commit consists of these smaller commits:
Gateway: SessionID to be a method for thread safety
This commit breaks the SessionID field of the Gateway struct to
be thread-safe by wrapping its access with a read-write mutex.
As this is a bug fix, it is reasonable of a breaking change
Heart: Allow later binding of event channel
Voice: Use the new Heart API
Heart: Fixed data races
Heart: Allow changing pace, thread-safe Heartbeat
This commit moved ExecuteWebhookData from package api to package webhook
inside package api. This change required splitting the multipart
abstractions away from package api, so they are now inside package
sendpart in utils.
This commit will break code that uploads anything, as the type name is
now sendpart.File from api.SendMessageFile. The behavior should be the
same as before.
* Rate: don't sleep if sleep exceeds context deadline
* Httputil: add Client.Timeout
* Bot: set default API timeout to 5 minutes
* Rate: reduce calls to time.Now in Acquire
* API: Optimize to use deadline instead of recalculating
Co-authored-by: diamondburned <datutbrus@gmail.com>
This commit refactors both wsutil, the normal Gateway and the Voice
Gateway to have better closing behavior, which should assume less and
cover edge cases completely.
This commit removes the thread safety requirement that Conn
implementations must satisfy. It moves the mutex guards as well as the
multiple close wrapper over to the Websocket wrapper instead.
This commit fixes race conditions in both package voice, package
voicegateway and package gateway.
Originally, several race conditions exist when both the user's and the
pacemaker's goroutines both want to do several things to the websocket
connection. For example, the user's goroutine could be writing, and the
pacemaker's goroutine could trigger a reconnection. This is racey.
This issue is partially fixed by removing the pacer loop from package
heart and combining the ticker into the event (pacemaker) loop itself.
Technically, a race condition could still be triggered with care, but
the API itself never guaranteed any of those. As events are handled
using an internal loop into a channel, a race condition will not be
triggered just by handling events and writing to the websocket.