Skip to content

fix: add timeout to IsPortActive to prevent macOS hangs - #8147

Merged
rfay merged 3 commits into
mainfrom
20260215_rfay_macos_hang
Feb 17, 2026
Merged

rfay merged 3 commits into
mainfrom
20260215_rfay_macos_hang

Conversation

@rfay

@rfay rfay commented Feb 15, 2026

Copy link
Copy Markdown
Member

The Issue

macOS CI tests (Lima, Rancher Desktop, and potentially OrbStack) hang indefinitely during ddev start in the CheckRouterPorts → IsPortActive code path. The hang occurs in net.DialTimeout("tcp", "127.0.0.1:PORT", 0) where the zero timeout means no deadline at all.

On macOS with VM-based Docker providers, ports can be in a state where the TCP SYN gets no response (neither RST nor SYN-ACK) — likely due to the port forwarding layer (Lima hostagent, etc.) having a port bound but not actively responding. With no timeout, the TCP connect retries indefinitely.

Goroutine dumps from two separate CI machines (Lima and Rancher Desktop) confirmed the identical hang:

net.DialTimeout(...)
  netutil.IsPortActive()        ← netutil.go:32
  ddevapp.CheckRouterPorts()    ← router.go:563
  ddevapp.StartDdevRouter()     ← router.go:129
  ddevapp.(*DdevApp).Start()

This latent bug was likely triggered by the Go 1.25 → 1.26 upgrade on CI machines, which may have changed internal TCP connect behavior in the net package (Go 1.26 added new Dialer.DialTCP/DialIP methods, suggesting internal dial path refactoring).

How This PR Solves The Issue

Changes dialTimeout default from 0 (infinite) to 1 * time.Second in IsPortActive. This is generous for a localhost port check — active ports respond in <1ms — while preventing indefinite hangs when ports are unresponsive.

The existing WSL2 case keeps its 200ms timeout, which was already tuned for its specific mirrored networking behavior.

Manual Testing Instructions

  1. ddev start on macOS with any VM-based Docker provider (Lima, Colima, OrbStack, Rancher Desktop)
  2. Verify startup completes without hanging at "Starting ddev-router"
  3. Verify port conflict detection still works: start something on port 80, then ddev start — it should report the conflict within ~1 second

Automated Testing Overview

No new tests needed. IsPortActive is exercised by existing integration tests (TestRouterPorts in router_test.go). The fix changes a timeout value, not logic — active ports still respond in <1ms, and the 1s timeout only affects the failure/hang case which was previously infinite.

Release/Deployment Notes

This is a one-line change with no behavioral impact for normal operation. Port checks that previously returned instantly will continue to do so. The only difference is that unresponsive ports now timeout after 1 second instead of hanging indefinitely.

PR #8146 (revert of #8128) can be closed — the port check skip for remote Docker hosts was not the cause of the hangs.

@github-actions

github-actions Bot commented Feb 15, 2026 •

Copy link
Copy Markdown

@rfay
rfay requested a review from stasadev February 16, 2026 04:31
Comment thread pkg/netutil/netutil.go Outdated
Comment on lines 21 to 23
if nodeps.IsWSL2() {
dialTimeout = 200 * time.Millisecond
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I imagine we should just remove the WSL2 stanza.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wonder if 200ms could be used everywhere to make the process faster.

1 second is enough, but if it could get stuck for every port, then it will be noticeable.

@stasadev stasadev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me.

rfay and others added 3 commits February 16, 2026 14:35
IsPortActive used a zero timeout (no deadline) for net.DialTimeout on
non-WSL2 platforms. On macOS with VM-based Docker providers (Lima,
OrbStack, Rancher Desktop), ports can be in a state where the TCP SYN
gets no response, causing the connect to hang indefinitely. This was
triggered by the Go 1.25->1.26 upgrade on CI machines.

A 1-second timeout is generous for localhost port checks (active ports
respond in <1ms) while preventing indefinite hangs.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@rfay
rfay force-pushed the 20260215_rfay_macos_hang branch from 105492c to f2364ab Compare February 16, 2026 21:36
@rfay
rfay merged commit dba0627 into main Feb 17, 2026
31 of 32 checks passed
@rfay
rfay deleted the 20260215_rfay_macos_hang branch February 17, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants