mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-15 18:20:11 +00:00
Attempt at a more resilient shard handler
Signed-off-by: Ske <voltasalt@gmail.com>
This commit is contained in:
parent
8b948bcfbb
commit
6ea1309ae0
2 changed files with 46 additions and 14 deletions
|
|
@ -74,6 +74,7 @@ namespace Myriad.Gateway
|
|||
try
|
||||
{
|
||||
await ConnectInner();
|
||||
|
||||
await HandleConnectionOpened();
|
||||
|
||||
while (_conn.State == WebSocketState.Open)
|
||||
|
|
@ -84,7 +85,7 @@ namespace Myriad.Gateway
|
|||
|
||||
await _stateManager.HandlePacketReceived(packet);
|
||||
}
|
||||
|
||||
|
||||
await HandleConnectionClosed(_conn.CloseStatus, _conn.CloseStatusDescription);
|
||||
|
||||
_logger.Information("Shard {ShardId}: Reconnecting after delay {ReconnectDelay}",
|
||||
|
|
@ -92,6 +93,7 @@ namespace Myriad.Gateway
|
|||
|
||||
if (_reconnectDelay > TimeSpan.Zero)
|
||||
await Task.Delay(_reconnectDelay);
|
||||
_reconnectDelay = TimeSpan.Zero;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -121,10 +123,22 @@ namespace Myriad.Gateway
|
|||
|
||||
private async Task ConnectInner()
|
||||
{
|
||||
await _ratelimiter.Acquire(_info.ShardId);
|
||||
while (true)
|
||||
{
|
||||
await _ratelimiter.Acquire(_info.ShardId);
|
||||
|
||||
_logger.Information("Shard {ShardId}: Connecting to WebSocket", _info.ShardId);
|
||||
await _conn.Connect(_url, default);
|
||||
_logger.Information("Shard {ShardId}: Connecting to WebSocket", _info.ShardId);
|
||||
try
|
||||
{
|
||||
await _conn.Connect(_url, default);
|
||||
break;
|
||||
}
|
||||
catch (WebSocketException e)
|
||||
{
|
||||
_logger.Error(e, "Shard {ShardId}: Error connecting to WebSocket, retrying in 5 seconds...", _info.ShardId);
|
||||
await Task.Delay(TimeSpan.FromSeconds(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task DisconnectInner(WebSocketCloseStatus closeStatus)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue