Skip to content
Closed
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
17 changes: 3 additions & 14 deletions pkg/port/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,10 @@ func TestProto(t *testing.T, proto string, d port.ParentDriver) {

func testProtoWithPID(t *testing.T, proto string, d port.ParentDriver, childPID int) {
ensureDeps(t, "nsenter", "ip", "nc")
// [child]parent

pairs := map[int]int{
// FIXME: flaky
80: (childPID + 80) % 60000,
8080: (childPID + 8080) % 60000,
}
if proto == "tcp" {
for _, parentPort := range pairs {
var d net.Dialer
d.Timeout = 50 * time.Millisecond
_, err := d.Dial(proto, fmt.Sprintf("127.0.0.1:%d", parentPort))
if err == nil {
t.Fatalf("port %d is already used?", parentPort)
}
}
80: 0,
8080: 0,
}
Comment on lines 142 to 145
Copy link

Copilot AI Dec 3, 2025

Choose a reason for hiding this comment

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

Setting ParentPort to 0 will cause AddPort() to fail validation. The validation in pkg/port/portutil/portutil.go:135 explicitly rejects port values <= 0:

if spec.ParentPort <= 0 || spec.ParentPort > 65535 {
    return fmt.Errorf("invalid ParentPort: %q", spec.ParentPort)
}

The test will fail at line 221 in testProtoRoutine when d.AddPort() returns this validation error.

To fix the flaky test, you need a different approach that ensures the port is free before using it, such as:

  1. Finding an available port dynamically (e.g., binding to port 0 temporarily to get an OS-assigned port, then closing and using that port number)
  2. Using a port allocation helper that checks availability
  3. Using a wider range or better randomization in the previous formula to reduce collision probability

Copilot uses AI. Check for mistakes.

t.Logf("namespace pid: %d", childPID)
Expand Down
Loading