3.0.2 EndOfStreamException: Attempted to read past the end of the stream.
Closed this issue · 10 comments
Updated from 3.0.1, immediately got this error:
EndOfStreamException: Attempted to read past the end of the stream.
MessagePack.MessagePackReader.get_NextCode () (at C:/Users/_/Documents/WorkUnity/_/Assets/Scripts/MessagePack/MessagePackReader.cs:109)
MessagePack.Formatters.Shared.Models.NetworkMessageBaseFormatter.Deserialize (MessagePack.MessagePackReader& reader, MessagePack.MessagePackSerializerOptions options) (at Assets/_/Scripts/Shared/Generated/MessagePackGenerated.cs:1213)
MessagePack.MessagePackSerializer.Deserialize[T] (MessagePack.MessagePackReader& reader, MessagePack.MessagePackSerializerOptions options) (at C:/Users/_/Documents/WorkUnity/_/Assets/Scripts/MessagePack/MessagePackSerializer.cs:250)
Rethrow as MessagePackSerializationException: Failed to deserialize Shared.Models.NetworkMessageBase value.
MessagePack.MessagePackSerializer.Deserialize[T] (MessagePack.MessagePackReader& reader, MessagePack.MessagePackSerializerOptions options) (at C:/Users/_/Documents/WorkUnity/_/Assets/Scripts/MessagePack/MessagePackSerializer.cs:255)
MessagePack.MessagePackSerializer.Deserialize[T] (System.ReadOnlyMemory`1[T] buffer, MessagePack.MessagePackSerializerOptions options, System.Threading.CancellationToken cancellationToken) (at C:/Users/_/Documents/WorkUnity/_/Assets/Scripts/MessagePack/MessagePackSerializer.cs:274)
Shared.Services.NetworkMessageSerializer.GetNetworkMessageType (System.ArraySegment`1[T] message) (at Assets/_/Scripts/Shared/Services/NetworkMessageSerializer.cs:16)
Client.Services.PlayerConnection.OnMessageReceived (System.Byte[] message) (at Assets/_/Scripts/Client/Services/PlayerConnection.cs:163)
Client.Services.PlayerConnection.OnMessageReceived (MikeSchweitzer.WebSocket.WebSocketConnection connection, MikeSchweitzer.WebSocket.WebSocketMessage message) (at Assets/_/Scripts/Client/Services/PlayerConnection.cs:158)
MikeSchweitzer.WebSocket.WebSocketConnection.OnMessageReceived (MikeSchweitzer.WebSocket.WebSocketMessage message) (at Assets/unity-websocket/Runtime/WebSocketConnection.cs:371)
MikeSchweitzer.WebSocket.Internal.DotNetWebSocket.ProcessIncomingMessages () (at Assets/unity-websocket/Runtime/Internal/DotNetWebSocket.cs:257)
MikeSchweitzer.WebSocket.Internal.DotNetWebSocket.ProcessMessagesAsync () (at Assets/unity-websocket/Runtime/Internal/DotNetWebSocket.cs:156)
MikeSchweitzer.WebSocket.WebSocketConnection.MainLoopAsync () (at Assets/unity-websocket/Runtime/WebSocketConnection.cs:216)
MikeSchweitzer.WebSocket.WebSocketConnection.Update () (at Assets/unity-websocket/Runtime/WebSocketConnection.cs:157)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <ed969b0e627d471da4848289f9c322df>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <84f0d810adef4e6c8deab33e4ae93f7c>:0)
Hm. That exception looks like it's coming from some other code you have that's trying to deserialize a websocket message into a MessagePack format, but it seems likely that 3.0.2 is now doing an incomplete read of messages before firing an event.
Go ahead and pin your version to 3.0.1 for now, I'll do some more testing. If you're not sure how to do that, you should be able to do this in your manifest.json:
"com.mikeschweitzer.websocket": "https://github.com/mikerochip/unity-websocket.git#3.0.1"
Yep, for some reason WebSocketMessage.Bytes returns array of length 0:
_connection.MessageReceived += OnMessageReceived;
private void OnMessageReceived(WebSocketConnection connection, WebSocketMessage message)
{
Debug.Log(message.Bytes.Length); // 0
}And you're positive your server is returning data? I just tested using my own test server https://github.com/mikerochip/server-websocket-tester and text as well as binary messages are coming through fine.
Can you give me more info?
Specifically what message is your server sending that is resulting in zero bytes on your websocket client?
3.0.1 works perfectly with the same server, I will try to check library diff for answers
It would be more helpful to get a sample message from your server, honestly. I just tried having my server send an overflow message and even that is coming through fine.
This is a message in base64 string (that I receive in 3.0.1 version, all messages are in binary format):
kwWaAQAAAAAAAACRAJCWlZIAzPCSAc0B4JICzQSwkgPNCWCSBM1dwJOSAMzwkgHNBLCSAs0JYJaSAMzwkgHNAtCSAs0EsJIDzQ4QkgTNLuCSBc1dwJQBAgMEkgID3AAYkwHCwpMCwsKTA8LDkwTCwpMFwsKTBsLCkwfCw5MIwsKTCcPCkwrDwpMLw8OTDMPCkw3DwpMOwsKTD8LCkxPCwpMUwsKTFcLDkxbDwpMXwsKTGMLCkxnCwpMaw8KTG8LD
Cool thanks, I'll use that to test whether it's getting cut off or something weird on the receiver.
OK nevermind, I see what I did, big goof on my part! I'm just not reading messages at all and was using old code in my tests. Working on a fix now.
Should be fixed as of https://github.com/mikerochip/unity-websocket/releases/tag/3.0.3
Apologies for that