Skip to content

Commit 07395c7

Browse files
committed
- Add size limits to websocket msg cache and background S3 uploader
1 parent 93a4260 commit 07395c7

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

GenOnlineService/BackgroundS3Uploader.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public enum ES3QueueUploadResult
2020
Success,
2121
Failed_InvalidUploadType,
2222
Failed_InvalidImage_Size,
23-
Failed_InvalidImage_Header
23+
Failed_InvalidImage_Header,
24+
Failed_QueueFull
2425
}
2526

2627
class S3QueuedUploadEntry
@@ -245,6 +246,13 @@ public static ES3QueueUploadResult QueueUpload(ES3UploadType uploadType, byte[]
245246
return ES3QueueUploadResult.Failed_InvalidUploadType;
246247
}
247248

249+
const int maxQueueSize = 5000;
250+
if (m_queueUploads.Count >= maxQueueSize)
251+
{
252+
Console.WriteLine($"Warning: S3 upload queue full ({maxQueueSize}), dropping upload for match {match_id}");
253+
return ES3QueueUploadResult.Failed_QueueFull;
254+
}
255+
248256
// queue it
249257
S3QueuedUploadEntry newUploadEntry = new S3QueuedUploadEntry(uploadType, fileBytes, match_id, user_id, slotIndexInLobby, screenshotTypeIfScreenshot); ;
250258
m_queueUploads.Enqueue(newUploadEntry);

GenOnlineService/Constants.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,15 @@ public void QueueWebsocketSend(byte[] bytesJSON)
637637
}
638638
else
639639
{
640-
m_lstPendingWebsocketSends.Enqueue(bytesJSON);
640+
const int maxQueueSize = 1000;
641+
if (m_lstPendingWebsocketSends.Count < maxQueueSize)
642+
{
643+
m_lstPendingWebsocketSends.Enqueue(bytesJSON);
644+
}
645+
else
646+
{
647+
Console.WriteLine($"Warning: Websocket send queue full for user {m_UserID}, dropping message");
648+
}
641649
}
642650
}
643651

@@ -679,7 +687,6 @@ public async Task TickWebsocket()
679687
}
680688
}
681689

682-
// TODO_CACHE: Size limit this?
683690
ConcurrentQueue<byte[]> m_lstPendingWebsocketSends = new ConcurrentQueue<byte[]>();
684691

685692
public void NotifyFriendslistDirty()

0 commit comments

Comments
 (0)