+
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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions RLBotCS/Server/FlatBuffersServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ChannelWriter<IBridgeMessage> bridge

private void AddSession(TcpClient client)
{
Channel<SessionMessage> sessionChannel = Channel.CreateUnbounded<SessionMessage>();
Channel<SessionMessage> sessionChannel = Channel.CreateBounded<SessionMessage>(60);
client.NoDelay = true;

int clientId = client.Client.Handle.ToInt32();
Expand Down Expand Up @@ -96,7 +96,11 @@ private async Task HandleServer()
while (true)
{
TcpClient client = await _context.Server.AcceptTcpClientAsync();
AddSession(client);

lock (_context)
{
AddSession(client);
}
}
}
catch (Exception e)
Expand Down
19 changes: 5 additions & 14 deletions RLBotCS/Server/ServerMessage/DistributeGamePacket.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using RLBot.Flat;
using RLBot.Flat;
using RLBotCS.ManagerTools;

namespace RLBotCS.Server.ServerMessage;
Expand Down Expand Up @@ -28,24 +28,15 @@ private static void DistributeBallPrediction(ServerContext context, GamePacketT
lastTouch,
packet.MatchInfo.WorldGravityZ
);

foreach (var (writer, _) in context.Sessions.Values)
{
SessionMessage message = new SessionMessage.DistributeBallPrediction(prediction);
writer.TryWrite(message);
}
context.DistributeMessage(new SessionMessage.DistributeBallPrediction(prediction));
}

private static void DistributeState(ServerContext context, GamePacketT packet)
{
context.LastTickPacket = packet;
foreach (var (writer, _) in context.Sessions.Values)
{
SessionMessage message = new SessionMessage.DistributeGameState(
context.LastTickPacket
);
writer.TryWrite(message);
}
context.DistributeMessage(
new SessionMessage.DistributeGameState(context.LastTickPacket)
);
}

public ServerAction Execute(ServerContext context)
Expand Down
2 changes: 1 addition & 1 deletion RLBotCS/Server/ServerMessage/SendMatchComm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public ServerAction Execute(ServerContext context)

if (context.LastTickPacket is null)
{
context.Logger.LogWarning("Received MatchComm before receiving a GameTickPacket.");
context.Logger.LogWarning("Received MatchComm before receiving a GamePacket.");
return ServerAction.Continue;
}

Expand Down
27 changes: 27 additions & 0 deletions RLBotCS/Server/ServerMessage/ServerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,31 @@ public Dictionary<
/// The BridgeHandler's config may contain updated names, e.g. "Nexto (2)",
/// and updated loadouts.</summary>
public MatchConfigurationT? MatchConfig { get; set; }

public readonly Dictionary<int, uint> MissedMessagesCount = new();

public void DistributeMessage(SessionMessage message)
{
foreach (var (id, (writer, _)) in Sessions)
{
if (!writer.TryWrite(message))
{
uint missedMessages = MissedMessagesCount.GetValueOrDefault(id) + 1;
MissedMessagesCount[id] = missedMessages;

// Log warning with exponential backoff,
// e.g. every 10, 100, 1000, etc. messages missed
// (including the first missed message)
uint powerOfTen = (uint)Math.Pow(10, Math.Ceiling(Math.Log10(missedMessages)));
if (missedMessages == powerOfTen)
{
Logger.LogWarning(
"Session {}'s outbound message queue is full ({} messages missed)",
id,
missedMessages
);
}
}
}
}
}
1 change: 1 addition & 0 deletions RLBotCS/Server/ServerMessage/SessionClosed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public ServerAction Execute(ServerContext context)
{
context.Bridge.TryWrite(new RemoveClientRenders(ClientId));
context.Sessions.Remove(ClientId);
context.MissedMessagesCount.Remove(ClientId);

return ServerAction.Continue;
}
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载