{"record":{"id":"261a79db120d3cf8","repo":"XTLS/Xray-core","slug":"read-minecraft-keep-alive-w","errorCode":null,"errorMessage":"read minecraft keep-alive: %w","messagePattern":"read minecraft keep-alive: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/internet/finalmask/xmc/packet_stream.go","lineNumber":91,"sourceCode":"\t\t\tpayload, ok, err := parseCustomPayload(packet)\n\t\t\tif err != nil {\n\t\t\t\treturn 0, err\n\t\t\t}\n\t\t\tif !ok || len(payload) == 0 {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tn := copy(p, payload)\n\t\t\tif n < len(payload) {\n\t\t\t\ts.pending = append(s.pending[:0], payload[n:]...)\n\t\t\t}\n\t\t\treturn n, nil\n\t\t}\n\n\t\tif packet.packetID == configurationKeepAlive {\n\t\t\tvar id Long\n\t\t\tif err := packet.readFields(&id); err != nil {\n\t\t\t\treturn 0, fmt.Errorf(\"read minecraft keep-alive: %w\", err)\n\t\t\t}\n\t\t\tif s.isClient {\n\t\t\t\tif err := s.writeKeepAlive(id); err != nil {\n\t\t\t\t\treturn 0, err\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (s *packetStream) Write(p []byte) (int, error) {\n\tif len(p) == 0 {\n\t\treturn 0, nil\n\t}\n\n\ts.writeMu.Lock()\n\tdefer s.writeMu.Unlock()\n","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/packet_stream.go#L73-L109","documentation":"packetStream.Read received a packet with ID 0x04 (configuration keep-alive) but failed to decode its single Long (8-byte big-endian) payload. Since readPacket already delivered the body, this indicates the body is shorter than 8 bytes or otherwise malformed — a framing/state mismatch with the peer, not an I/O failure.","triggerScenarios":"Peer (client or server) writes a 0x04 packet whose data section is under 8 bytes, or the two sides disagree on packet ID assignments so a different packet is interpreted as a keep-alive.","commonSituations":"Version mismatch between client and server xmc builds that reassigned configuration packet IDs; a non-xmc Minecraft endpoint responding in the wrong protocol state; corrupted stream after middlebox interference.","solutions":["Pin both endpoints to the same library/protocol version","Confirm the endpoint is actually an xmc-compatible peer, not a vanilla Minecraft server","Capture the stream and verify 0x04 packets carry exactly 8 payload bytes","Close the connection; mid-stream decode corruption is not recoverable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"n, err := stream.Read(buf)\nif err != nil && strings.Contains(err.Error(), \"read minecraft keep-alive\") {\n    // protocol mismatch: peer is not speaking the expected configuration state\n    conn.Close()\n}","preventionTips":["Use identical xmc builds on both ends","Verify the remote is an xmc peer before wrapping","Add integration tests exercising keep-alive round trips"],"tags":["go","minecraft","protocol","keep-alive","decode"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}