From 0cca17f1a2d68d6341132eef4565ae8bde0e8bce Mon Sep 17 00:00:00 2001 From: Paulo Date: Wed, 18 Nov 2020 23:32:29 -0300 Subject: [PATCH] Add lock to InvalidSession --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 9f448c658..d53387afc 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -520,7 +520,15 @@ namespace Discord.WebSocket _sessionId = null; _lastSeq = 0; - await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents).ConfigureAwait(false); + await _shardedClient.AcquireIdentifyLockAsync(ShardId, _connection.CancelToken).ConfigureAwait(false); + try + { + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions, gatewayIntents: _gatewayIntents).ConfigureAwait(false); + } + finally + { + _shardedClient.ReleaseIdentifyLock(); + } } break; case GatewayOpCode.Reconnect: