+
Skip to content

Fix memory leak #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 15, 2025
Merged

Fix memory leak #130

merged 2 commits into from
Jul 15, 2025

Conversation

VirxEC
Copy link
Collaborator

@VirxEC VirxEC commented Jul 8, 2025

When a session stops receiving messages, we would keep saving all the missed messages would would cause memory usage to balloon. This PR protects core from these misbehaving sessions.

This PR adds back pressure on FlatbufferServer by limiting sessionChannel to storing a max of 60 items. I think this is a fair number, but if there's crazy amounts of MatchComm messages being sent around it might be be enough? The limit can be increased later if needed.

If a session misses a message, a warning is printed. In order to not spam the console, exponential backoff has been implemented to a power of 10 (do we want to do the power of 2?) so it will print on the 1st missed message, then the 10th, 100th, 1000th, etc. Example of this warning:

image

This warning has only been implemented for when BallPrediction/GamePacket are added to sessionChannel because of the high frequency with which they are consistently sent, adding it to these alone is likely enough to flag the problem.

@NicEastvillage
Copy link
Contributor

What can cause a Session to stop receiving internal messages?

@VirxEC
Copy link
Collaborator Author

VirxEC commented Jul 15, 2025

The likely case this would trigger is, for example, if a bot/script/match manager were to stop reading from a socket without closing the connection. Previously, RLBotServer's memory usage would explode as it saved every missed message. Now, we store up to 60 and discard any further missed messages.

@VirxEC
Copy link
Collaborator Author

VirxEC commented Jul 15, 2025

beta 12 of the GUI currently has this exact bug which causes the memory leak (although the bug has been fixed on master)

@NicEastvillage
Copy link
Contributor

I see. And the reason the messages pile up in the internal channel is that we want to make sure the client receives all messages - even old ones? Maybe we should consider changing that philosophy instead. The typical interfaces discards all non-latest game packets anyway.

@VirxEC
Copy link
Collaborator Author

VirxEC commented Jul 15, 2025

More just, that's just what happens when you use an unbounded channel. Also, we cant directly control the contents of the channel. Hence, we just stop storing the messages after a little bit instead of letting the unbounded channel grow forever.

@VirxEC
Copy link
Collaborator Author

VirxEC commented Jul 15, 2025

A properly functioning client should never encounter this case

@NicEastvillage
Copy link
Contributor

Good point. So it's a user error and we need a warning.

@VirxEC VirxEC merged commit 0ebeaf9 into master Jul 15, 2025
6 checks passed
@VirxEC VirxEC deleted the bound-chan branch July 15, 2025 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载