Browse Source

fixed a deadlock in DiscordShardedClient during a failed Identify due to InvalidSession

pull/1761/head
yebafan 4 years ago
parent
commit
41fa91f01e
1 changed files with 23 additions and 12 deletions
  1. +23
    -12
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 23
- 12
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -554,25 +554,36 @@ namespace Discord.WebSocket
case GatewayOpCode.InvalidSession: case GatewayOpCode.InvalidSession:
{ {
await _gatewayLogger.DebugAsync("Received InvalidSession").ConfigureAwait(false); await _gatewayLogger.DebugAsync("Received InvalidSession").ConfigureAwait(false);
await _gatewayLogger.WarningAsync("Failed to resume previous session").ConfigureAwait(false);


_sessionId = null;
_lastSeq = 0;

if (_shardedClient != null)
if (_sessionId != null)
{ {
await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false);
try
{
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
}
finally
// Failed to resume
await _gatewayLogger.WarningAsync("Failed to resume previous session").ConfigureAwait(false);

_sessionId = null;
_lastSeq = 0;

if (_shardedClient != null)
{ {
_shardedClient.ReleaseIdentifyLock();
await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false);
try
{
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
}
finally
{
_shardedClient.ReleaseIdentifyLock();
}
} }
else
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
} }
else else
{
// Failed to identify
await _gatewayLogger.WarningAsync("Failed to resume previous session").ConfigureAwait(false);
await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false); await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents, presence: BuildCurrentStatus()).ConfigureAwait(false);
}
} }
break; break;
case GatewayOpCode.Reconnect: case GatewayOpCode.Reconnect:


Loading…
Cancel
Save