Skip to content

Commit

Permalink
Clamp cache size
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Dec 19, 2024
1 parent 7e913e2 commit 25ff2ef
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Kook.Net.WebSocket/Entities/Messages/MessageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ internal class MessageCache
public MessageCache(KookSocketClient kook)
{
_size = kook.MessageCacheSize;
_messages = new ConcurrentDictionary<Guid, SocketMessage>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(_size * 1.05));
int dictSize = _size * 1.05 > int.MaxValue ? int.MaxValue : (int)(_size * 1.05);
_messages = new ConcurrentDictionary<Guid, SocketMessage>(ConcurrentHashSet.DefaultConcurrencyLevel, dictSize);
_orderedMessages = new ConcurrentQueue<(Guid MsgId, DateTimeOffset Timestamp)>();
}

Expand Down

0 comments on commit 25ff2ef

Please sign in to comment.