fix(battle-node): strip/prepend EIO3 type byte on binary WS frames
Engine.IO v3 frames over WebSocket prepend the packet-type byte (0x04 for Message) to BINARY frames, the binary analog of the leading digit on text frames. The real client honors this and our session was treating the entire binary frame as the Socket.IO attachment payload — the msgpack decoder saw 0x04 as a positive fixint and failed deserialization on every inbound msg event. Symmetric fix: strip 0x04 from inbound binary frames in BattleSession.RunAsync, prepend 0x04 to outbound binary frames in EncodeAndSendAsync. RawSocketIoTestClient gets the same on both directions so the integration test still exercises the same wire shape as a real client. Caught during v1 smoke walkthrough, after the WS upgrade started succeeding (101 Switching Protocols). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -66,7 +66,13 @@ internal sealed class RawSocketIoTestClient : IAsyncDisposable
|
||||
}
|
||||
await SendTextAsync($"{(int)EngineIoPacketType.Message}{text}", ct);
|
||||
foreach (var b in bins)
|
||||
await _ws.SendAsync(b, WebSocketMessageType.Binary, true, ct);
|
||||
{
|
||||
// EIO v3 binary frames are prefixed with the packet-type byte (0x04 = Message).
|
||||
var prefixed = new byte[b.Length + 1];
|
||||
prefixed[0] = (byte)EngineIoPacketType.Message;
|
||||
Buffer.BlockCopy(b, 0, prefixed, 1, b.Length);
|
||||
await _ws.SendAsync(prefixed, WebSocketMessageType.Binary, true, ct);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<string> ReceiveTextAsync(CancellationToken ct)
|
||||
@@ -92,7 +98,13 @@ internal sealed class RawSocketIoTestClient : IAsyncDisposable
|
||||
result = await _ws.ReceiveAsync(buffer, ct);
|
||||
ms.Write(buffer, 0, result.Count);
|
||||
} while (!result.EndOfMessage);
|
||||
return ms.ToArray();
|
||||
var raw = ms.ToArray();
|
||||
// EIO v3 binary frames are prefixed with the packet-type byte (0x04 = Message). Strip it.
|
||||
if (raw.Length > 0 && raw[0] == (byte)EngineIoPacketType.Message)
|
||||
{
|
||||
return raw.AsSpan(1).ToArray();
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
private Task SendTextAsync(string text, CancellationToken ct)
|
||||
|
||||
Reference in New Issue
Block a user