XTLS/Xray-core · error

failed to write raw icmp packet back to stack

Error message

failed to write raw icmp packet back to stack

What it means

ICMP handler fails injecting a synthesized raw IP packet (echo reply or error message) back into the gVisor stack via WriteRawPacket; the chained error means the stack rejected the re-encapsulated packet, so the ICMP response is dropped.

Solutions

  1. Inspect .Base(err) from stack.WriteRawPacket
  2. Verify the reconstructed IP header (version, checksum, length) matches the packet
  3. Ensure defaultNIC is up and the packet protocol matches ipProtocol
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at proxy/tun/stack_gvisor_icmp_handler.go:85 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of XTLS/Xray-core@7d214f8b09 (2026-08-15). Data as JSON: /api/errors/de55322715c61bea. Report an issue: GitHub.

Appendix: source

Thrown at proxy/tun/stack_gvisor_icmp_handler.go:85

			TTL:         64,
			Protocol:    uint8(transportProtocol),
			SrcAddr:     srcIP,
			DstAddr:     dstIP,
		})
		ipHdr.SetChecksum(^ipHdr.CalculateChecksum())
	} else {
		ipHdr := header.IPv6(pkt.NetworkHeader().Push(header.IPv6MinimumSize))
		ipHdr.Encode(&header.IPv6Fields{
			PayloadLength:     uint16(len(message)),
			TransportProtocol: transportProtocol,
			HopLimit:          64,
			SrcAddr:           srcIP,
			DstAddr:           dstIP,
		})
	}

	if err := t.stack.WriteRawPacket(defaultNIC, ipProtocol, buffer.MakeWithView(pkt.ToView())); err != nil {
		return errors.New("failed to write raw icmp packet back to stack", err)
	}

	return nil
}

func transportPacketBytes(pkt *stack.PacketBuffer) []byte {
	headerBytes := pkt.TransportHeader().Slice()
	payloadBytes := pkt.Data().AsRange().ToSlice()
	message := make([]byte, len(headerBytes)+len(payloadBytes))
	copy(message, headerBytes)
	copy(message[len(headerBytes):], payloadBytes)
	return message
}

View on GitHub (pinned to 7d214f8b09)