Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pkg/tunnel/local_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,22 @@ func TestLocalTunnel_ContextCancellation(t *testing.T) {
addr := tun.Addr()
cancel()

time.Sleep(100 * time.Millisecond)
_, err = net.DialTimeout("tcp", addr, 500*time.Millisecond)
if err == nil {
t.Error("expected connection to be refused after context cancellation")
// The listener is closed asynchronously after cancellation.
deadline := time.After(2 * time.Second)
ticker := time.NewTicker(10 * time.Millisecond)
defer ticker.Stop()

for {
conn, err := net.DialTimeout("tcp", addr, 50*time.Millisecond)
if err != nil {
return
}
Comment on lines +193 to +195

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dial failure bypasses deadline

The loop returns on a dial error before checking the two-second deadline. If the deadline fires while DialTimeout is still running and the listener closes afterward, the test passes even though shutdown exceeded the intended bound. Check the deadline or elapsed time before treating the dial failure as success.

_ = conn.Close()
select {
case <-deadline:
t.Fatal("listener still accepting connections after context cancellation")
case <-ticker.C:
}
}
}

Expand Down
Loading