From 45a6d96c6a9e4f5bc078b41b53e1345bae6329fe Mon Sep 17 00:00:00 2001 From: Kevin Krakauer Date: Thu, 13 Jun 2024 14:23:46 -0700 Subject: [PATCH] netstack: panic early with TCP state for debugging We've seen panics in `segment.payloadSize()` stemming from what seems to be an out of sync write list and sender state. That is, SndUna and SndNxt indicate there are unacknowledged bytes remaining, but the write list -- which contains all sent bytes until they're acknowledged -- is empty. Panic early with TCP state for debugability. PiperOrigin-RevId: 643120793 --- pkg/tcpip/transport/tcp/snd.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/tcpip/transport/tcp/snd.go b/pkg/tcpip/transport/tcp/snd.go index 4e51d8b03..2301ae905 100644 --- a/pkg/tcpip/transport/tcp/snd.go +++ b/pkg/tcpip/transport/tcp/snd.go @@ -1572,8 +1572,11 @@ func (s *sender) handleRcvdSegment(rcvdSeg *segment) { // segments (which are always at the end of list) that // have no data, but do consume a sequence number. seg := s.writeList.Front() - datalen := seg.logicalLen() + if seg == nil { + panic(fmt.Sprintf("invalid state: there are %d unacknowledged bytes left, but the write list is empty:\n%+v", ackLeft, s.TCPSenderState)) + } + datalen := seg.logicalLen() if datalen > ackLeft { prevCount := s.pCount(seg, s.MaxPayloadSize) seg.TrimFront(ackLeft)