XTLS/Xray-core · error
write packet ID: %w
Error message
write packet ID: %w
What it means
Returned by encodePacket when writing the packet ID varint into the in-memory frame bytes.Buffer fails. As with the frame-length write, bytes.Buffer writes are infallible for the shipped Varint type, making this a defensive error path satisfying the field.writeTo contract rather than a realistic failure.
Source
Thrown at transport/internet/finalmask/xmc/protocol.go:420
}
if dataBuf.Len() > maxPacketDataLength {
return nil, fmt.Errorf("write packet: bad length: %d", dataBuf.Len())
}
packetIDVarint := Varint(packetID)
bodyLength := varintSize(packetIDVarint) + dataBuf.Len()
if bodyLength > maxPacketBodyLength {
return nil, fmt.Errorf("write packet: bad length: %d", bodyLength)
}
var frame bytes.Buffer
frame.Grow(varintSize(Varint(bodyLength)) + bodyLength)
frameLength := Varint(bodyLength)
if err := frameLength.writeTo(&frame); err != nil {
return nil, fmt.Errorf("write packet length: %w", err)
}
if err := packetIDVarint.writeTo(&frame); err != nil {
return nil, fmt.Errorf("write packet ID: %w", err)
}
frame.Write(dataBuf.Bytes())
return frame.Bytes(), nil
}
func writeFull(w io.Writer, p []byte) error {
for len(p) > 0 {
n, err := w.Write(p)
if n > 0 {
p = p[n:]
}
if err != nil {
return err
}
if n == 0 {
return io.ErrShortWrite
}
}View on GitHub (pinned to 7d214f8b09)
Solutions
- Inspect the wrapped error for the real cause if using custom field types
- Verify the local tree has not modified Varint.writeTo
- Report upstream if reproducible with stock types
Defensive patterns
Strategy: try-catch
Prevention
- Recognize this as an unreachable defensive path with stock types
- Audit custom field implementations if it ever appears
When it happens
Trigger: packetIDVarint.writeTo(&frame) returning an error at protocol.go:420 — unreachable with stock field types writing to bytes.Buffer.
Common situations: Not observed in production; only reachable via custom field implementations or a modified encoder.
Related errors
- write packet length: %w
- write packet field: %w
- write packet: bad length: %d
- no QueryStrategy available for
- Cannot start all fake dns pools
AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15).
Data as JSON: /api/errors/431c6b0463386140.
Report an issue: GitHub.