Skip to content
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

WebSocketException: The header part of a frame could not be read. #569

Open
starfi5h opened this issue Jun 7, 2022 · 2 comments
Open

WebSocketException: The header part of a frame could not be read. #569

starfi5h opened this issue Jun 7, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@starfi5h
Copy link
Collaborator

starfi5h commented Jun 7, 2022

This seems to report by some players. They can join for the first time, but on the second time they can't join and stuck on loading factory message.
I finally found a way to reproduce it, at least on my machine.

  1. Create a large fake payload on FactoryData packet. I created a byte array of 100MB.
  2. Let client login by ngrok address to simulate bad network condition.
  3. Let host move around or do some stuff after sending FactoryData packet to client. The client will error after a period and disconnet.

Client log:

[Info   :NebulaMultiplayerMod] Requested factory for planet Alpheratz III号星 (ID: 103) from host
[Debug  :NebulaMultiplayerMod] Packet Sent: FactoryLoadRequest
[Warning:NebulaMultiplayerMod] 2022/6/7 上午 12:04:37|Fatal|<>c__DisplayClass174_0.<startReceiving>b__2:0|WebSocketSharp.WebSocketException: The header part of a frame could not be read.
                             at WebSocketSharp.WebSocketFrame.processHeader (System.Byte[] header) [0x0001f] in <a2974eceb86942248aa42ebfa46be6d0>:IL_001F 
                             at WebSocketSharp.WebSocketFrame+<>c__DisplayClass71_0.<readHeaderAsync>b__0 (System.Byte[] bytes) [0x00001] in <a2974eceb86942248aa42ebfa46be6d0>:IL_0001 
                             at WebSocketSharp.Ext+<>c__DisplayClass54_0.<ReadBytesAsync>b__0 (System.IAsyncResult ar) [0x0008e] in <a2974eceb86942248aa42ebfa46be6d0>:IL_008E 
[Info   :NebulaMultiplayerMod] 2022/6/7 上午 12:04:37|Debug|WebSocket.closeHandshake:0|Was clean?: False
                             sent: False
                             received: False

Host log:

[Debug  :NebulaMultiplayerMod] Packet Received: FactoryLoadRequest
[Info   :NebulaMultiplayerMod] Sent 1050157 bytes of data for PlanetFactory Alpheratz III号星 (ID: 103)
[Debug  :NebulaMultiplayerMod] Packet Sent: FactoryData
[Debug  :NebulaMultiplayerMod] Packet Sent: VegeMinedPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: VegeMinedPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: GameHistoryResearchUpdatePacket
[Debug  :NebulaMultiplayerMod] Packet Sent: CreatePrebuildsRequest
[Debug  :NebulaMultiplayerMod] Packet Sent: NewDroneOrderPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: VegeMinedPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: GameHistoryResearchUpdatePacket
[Debug  :NebulaMultiplayerMod] Packet Sent: BuildEntityRequest
[Debug  :NebulaMultiplayerMod] Packet Sent: VegeMinedPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: PlayerSandCount
[Debug  :NebulaMultiplayerMod] Packet Sent: NewDroneOrderPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: GameHistoryResearchUpdatePacket
[Debug  :NebulaMultiplayerMod] Packet Sent: CreatePrebuildsRequest
[Debug  :NebulaMultiplayerMod] Packet Sent: NewDroneOrderPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: GameHistoryResearchUpdatePacket
[Debug  :NebulaMultiplayerMod] Packet Sent: BuildEntityRequest
[Debug  :NebulaMultiplayerMod] Packet Sent: VegeMinedPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: VegeMinedPacket
[Debug  :NebulaMultiplayerMod] Packet Sent: PlayerSandCount
[Debug  :NebulaMultiplayerMod] Packet Sent: NewDroneOrderPacket
[Info   :NebulaMultiplayerMod] 2022/6/7 上午 12:04:34|Debug|WebSocket.closeHandshake:0|Was clean?: False
                             sent: False
                             received: False
[Info   :NebulaMultiplayerMod] Client disconnected: ef000229256142359b4c32abf5b3c0dc, reason: 
[Warning:NebulaMultiplayerMod] 2022/6/7 上午 12:04:34|Error|WebSocket.send:0|The connection is closing.
[Info   :NebulaMultiplayerMod] Client disconnected because of an error: ef000229256142359b4c32abf5b3c0dc, reason: 
[Warning:NebulaMultiplayerMod] 2022/6/7 上午 12:04:34|Fatal|<>c__DisplayClass174_0.<startReceiving>b__2:0|System.ObjectDisposedException: Cannot access a disposed object.
                           Object name: 'System.Net.Sockets.NetworkStream'.
                             at System.Net.Sockets.NetworkStream.EndRead (System.IAsyncResult asyncResult) [0x00015] in <0813754e7cfa415ebfedff172c2dd6e0>:IL_0015 
                             at WebSocketSharp.Ext+<>c__DisplayClass54_0.<ReadBytesAsync>b__0 (System.IAsyncResult ar) [0x00002] in <a2974eceb86942248aa42ebfa46be6d0>:IL_0002 
[Warning:NebulaMultiplayerMod] 2022/6/7 上午 12:04:34|Error|WebSocket.send:0|The connection is closing.
[Info   :NebulaMultiplayerMod] Client disconnected because of an error: ef000229256142359b4c32abf5b3c0dc, reason: 
[Info   :NebulaMultiplayerMod] 2022/6/7 上午 12:04:34|Info |WebSocket.close:0|The connection has already been closed.
[Warning:NebulaMultiplayerMod] Cannot send packet to a Closed connection 3363
[Debug  :BulletTime] Exit pause mode, duration: 768 ticks.
[Warning:NebulaMultiplayerMod] PlayerDisconnected NOT CALLED!
[Warning:NebulaMultiplayerMod] PlayerDisconnected NOT CALLED!
[Info   :NebulaMultiplayerMod] Updated Discord activity
@starfi5h starfi5h added the bug Something isn't working label Jun 7, 2022
@JamzOJamz
Copy link

JamzOJamz commented Jun 16, 2022

I'm using websocket-sharp in my own Bepinex project and getting the same error. It always happens after a variable amount of time, usually 5 minutes, when sending a message to the server. .. Did you guys ever find a fix? Thanks.

@starfi5h
Copy link
Collaborator Author

@JamzOhJamz In our case this seems to be related with WebSocketServiceManager.
Sometimes when sending a large fragments of packet, ping frame may not get respond within 1 sec (default value) if the network condition is not good, thus the session gets clean up by WebSocketServiceManager.
So I try to increase socket.WaitTime for server to avoid this situation, seems solved during my testing.

socket.KeepClean = true;
socket.WaitTime = TimeSpan.FromSeconds(20);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants