{"record":{"id":"a7151ed0df26920c","repo":"XTLS/Xray-core","slug":"write-uuid-w","errorCode":null,"errorMessage":"write UUID: %w","messagePattern":"write UUID: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"transport/internet/finalmask/xmc/protocol.go","lineNumber":305,"sourceCode":"\t*v = b == 1\n\treturn nil\n}\n\nfunc (v *Boolean) writeTo(w io.Writer) error {\n\tvalue := byte(0)\n\tif *v {\n\t\tvalue = 1\n\t}\n\tif _, err := w.Write([]byte{value}); err != nil {\n\t\treturn fmt.Errorf(\"write boolean: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (v *UUID) writeTo(w io.Writer) error {\n\t_, err := w.Write(v[:])\n\tif err != nil {\n\t\treturn fmt.Errorf(\"write UUID: %w\", err)\n\t}\n\treturn nil\n}\n\ntype Bytes []byte\n\nfunc (v *Bytes) readFrom(r io.Reader) error {\n\tvar length Varint\n\terr := length.readFrom(r)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"read bytes: %w\", err)\n\t}\n\n\tif length < 0 || length >= 1024 {\n\t\treturn fmt.Errorf(\"read bytes: invalid size: %d\", length)\n\t}\n\n\tbuf := make([]byte, length)","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/XTLS/Xray-core/blob/7d214f8b094f75322fa3990f8aadad1c912f24f5/transport/internet/finalmask/xmc/protocol.go#L287-L323","documentation":"UUID.writeTo writes the fixed 16-byte UUID to the io.Writer and wraps any Write failure with this message. Like other 'write X: %w' errors in protocol.go, it is purely an I/O failure on the underlying connection or buffer, not a data problem.","triggerScenarios":"Writing a handshake/login packet containing the profile UUID when the TCP connection is already closed, reset, or past its write deadline.","commonSituations":"Peer disconnects between the padding handshake and the login phase; mobile network switching dropping the socket; proxy chain (Xray routing) closing the outbound while the xmc layer is still encoding.","solutions":["Unwrap the error to distinguish connection-closed (peer gone) from timeout (deadline) and handle accordingly.","Retry the whole connection at a higher level if the transport policy allows.","Set sane write timeouts before the login exchange.","Verify the remote actually speaks this Minecraft-based protocol on that port."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := uuidField.writeTo(w)\nif err != nil {\n    switch {\n    case errors.Is(err, net.ErrClosed), isBrokenPipe(err):\n        teardown(conn)\n    case isNetTimeout(err):\n        conn.SetWriteDeadline(time.Now().Add(biggerDeadline))\n    }\n}","preventionTips":["Provision write deadlines sized to RTT plus payload serialization time.","Detect peer shutdown via keepalive failures before writing.","Do not reuse a conn after any write error."],"tags":["go","network","io","protocol-framing"],"backgroundTag":null,"analyzedSha":"7d214f8b094f75322fa3990f8aadad1c912f24f5","analyzedAt":"2026-08-15T14:26:24.325Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}