XTLS/Xray-core · error
write bytes: %w
Error message
write bytes: %w
What it means
After the length prefix, Bytes.writeTo writes the payload slice and wraps any Write failure with this message. The payload itself is opaque; failure is always the underlying writer (connection closed/reset, deadline exceeded, or a custom writer erroring).
Source
Thrown at transport/internet/finalmask/xmc/protocol.go:362
}
func (v *RestBytes) writeTo(w io.Writer) error {
if _, err := w.Write(*v); err != nil {
return fmt.Errorf("write remaining bytes: %w", err)
}
return nil
}
func (v *Bytes) writeTo(w io.Writer) error {
length := Varint(len(*v))
err := length.writeTo(w)
if err != nil {
return fmt.Errorf("write bytes length: %w", err)
}
_, err = w.Write(*v)
if err != nil {
return fmt.Errorf("write bytes: %w", err)
}
return nil
}
func readByte(r io.Reader) (byte, error) {
var buf [1]byte
_, err := io.ReadFull(r, buf[:])
if err != nil {
return 0, fmt.Errorf("read byte: %w", err)
}
return buf[0], nil
}
func writePacket(w io.Writer, packetID int, fields ...field) error {
_, err := writePacketWithLength(w, packetID, fields...)
return errView on GitHub (pinned to 7d214f8b09)
Solutions
- On first write error, mark the connection dead and stop the write loop — subsequent writes will only fail again.
- Use write deadlines proportional to payload size.
- If errors appear immediately at connect, verify the endpoint and protocol version.
- Capture which packet ID was being written when the failure occurred for faster diagnosis.
Defensive patterns
Strategy: try-catch
Try / catch
if err := bytesField.writeTo(w); err != nil {
markConnDead() // first write failure is terminal
return fmt.Errorf("connection failed during payload write: %w", err)
} Prevention
- Never write again on a connection that returned a write error.
- Use deadlines scaled to payload size and link speed.
- Verify endpoint/protocol version when failures occur at connect time.
When it happens
Trigger: Writing the body of a byte-array field to a conn that has been closed by the peer or by local error handling; write deadline expiring mid-payload on slow links.
Common situations: Half-closed TCP after server restart; MTU/throughput issues making large writes exceed deadlines; concurrent close from a monitor goroutine.
Related errors
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/9184270145596f03.
Report an issue: GitHub.