MCCTeam / Minecraft-Console-Client

Lightweight console for Minecraft chat and automated scripts
https://mccteam.github.io
Other
1.67k stars 402 forks source link

[BUG] WebSocketBot tries to send different pieces of data simutaneously, causing an error #2804

Open DGCK81LNN opened 1 month ago

DGCK81LNN commented 1 month ago

Prerequisites

Minecraft Version

1.18.2

Console Client Version

20240906-276

Expected Behavior

The WebSocketBot should use a lock, request queue or something else to prevent webSocket.SendAsync() being called before the previous send operation finishes.

Actual Behavior

My bot was near a farm filled with mobs, and there were a lot of events being reported. The WebSocket connection constantly dies as the client reports System.InvalidOperationException: There is already one outstanding 'SendAsync' call for this WebSocket instance. ReceiveAsync and SendAsync can be called simultaneously, but at most one outstanding operation for each of them is allowed at the same time.

Steps to Reproduce the bug

I haven't found a stable way to reproduce the issue but my bot was near a lot of mobs while entity handling was enabled, and I was using MCC.js to control the bot.

Attach screenshot here (If applicable)

No response

Anythings that could help diagnosing the bug

The exception occured here: https://github.com/MCCTeam/Minecraft-Console-Client/blob/27e66433cdd1997a7ff69e0dfb7ca6d79646e30d/MinecraftClient/ChatBots/WebSocketBot.cs#L172-L174

Device

Desktop

Operating System

Windows

Server Address (If applicable)

No response