Skip to content

Commit d6ba994

Browse files
ayushr2gvisor-bot
authored andcommitted
Don't silently drop errors from tcp.Endpoint.handleListenSegment().
Previously, errors from `handleListenSegment` were silently ignored. This change logs a warning when `handleListenSegment` returns an error, providing better visibility into issues during TCP connection establishment. Fixes #4690 PiperOrigin-RevId: 804633135
1 parent fa67407 commit d6ba994

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

pkg/tcpip/transport/tcp/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ go_library(
207207
"//pkg/tcpip/transport/raw",
208208
"//pkg/waiter",
209209
"@com_github_google_btree//:go_default_library",
210+
"@org_golang_x_time//rate:go_default_library",
210211
],
211212
)
212213

pkg/tcpip/transport/tcp/dispatcher.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import (
1818
"encoding/binary"
1919
"fmt"
2020
"math/rand"
21+
"time"
2122

23+
"golang.org/x/time/rate"
24+
"gvisor.dev/gvisor/pkg/log"
2225
"gvisor.dev/gvisor/pkg/sleep"
2326
"gvisor.dev/gvisor/pkg/sync"
2427
"gvisor.dev/gvisor/pkg/tcpip"
@@ -253,6 +256,8 @@ func handleTimeWait(ep *Endpoint) {
253256
ep.mu.Unlock()
254257
}
255258

259+
var warnRateLimiter = rate.NewLimiter(rate.Every(time.Second), 1)
260+
256261
// handleListen is responsible for TCP processing for an endpoint in LISTEN
257262
// state.
258263
func handleListen(ep *Endpoint) {
@@ -274,9 +279,11 @@ func handleListen(ep *Endpoint) {
274279
break
275280
}
276281

277-
// TODO(gvisor.dev/issue/4690): Better handle errors instead of
278-
// silently dropping.
279-
_ = ep.handleListenSegment(ep.listenCtx, s)
282+
if err := ep.handleListenSegment(ep.listenCtx, s); err != nil {
283+
if warnRateLimiter.Allow() {
284+
log.Warningf("tcp.Endpoint.handleListenSegment() failed for packet [nic=%d, source=%s, dest=%s, protocol=%d]: %v", s.pkt.NICID, s.pkt.Network().SourceAddress(), s.pkt.Network().DestinationAddress(), s.pkt.NetworkProtocolNumber, err)
285+
}
286+
}
280287
s.DecRef()
281288
}
282289
}

test/runner/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,8 @@ func isWarning(line string) bool {
701701
case strings.Contains(line, "Rejecting attempt to open unix domain socket"):
702702
case strings.Contains(line, "Rejecting attempt to connect to unix domain socket"):
703703
case strings.Contains(line, "Rejecting attempt to create unix domain socket"):
704+
// Expected in some socket tests.
705+
case strings.Contains(line, "tcp.Endpoint.handleListenSegment() failed") && strings.Contains(line, "connection aborted"):
704706

705707
// Ignore clock frequency adjustment messages.
706708
case strings.Contains(line, "adjusted frequency from"):

0 commit comments

Comments
 (0)