Skip to content

fix: distinguish AddrInUse from transient IPv6 bind failures in port checker#2640

Merged
domenkozar merged 4 commits into
cachix:mainfrom
spireworks:fix/strict-port-false-positive-on-cache-miss
Mar 20, 2026
Merged

fix: distinguish AddrInUse from transient IPv6 bind failures in port checker#2640
domenkozar merged 4 commits into
cachix:mainfrom
spireworks:fix/strict-port-false-positive-on-cache-miss

Conversation

@sadjow

@sadjow sadjow commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes false-positive "Port X is already in use" errors when --strict-ports is enabled and the nix evaluation cache is invalidated.

  • bind_no_reuse now returns the actual io::Error instead of discarding it as ()
  • reserve_port only treats AddrInUse errors from the IPv6 bind as genuine port conflicts
  • Non-conflict IPv6 failures (transient OS state on macOS, permission errors) fall through to IPv4-only mode instead of failing the entire port check

Problem

On macOS, after a clean devenv up shutdown (all processes confirmed dead, lsof shows no listeners), restarting immediately can fail with "Port 6380 is already in use" but only when:

  1. The nix eval cache is invalidated (e.g. a file changed)
  2. --strict-ports is enabled

The port is not actually in use. lsof confirms nothing is listening and get_process_using_port finds no PID. The issue is that bind_no_reuse on [::1]:port can fail for non-AddrInUse reasons on macOS, and the previous code assumed any IPv6 bind failure meant the port was occupied.

Test plan

  • Added test_bind_no_reuse_returns_addr_in_use_error to verify error kind propagation
  • Added test_reserve_port_succeeds_when_ipv4_free to verify strict mode works on free ports
  • Added test_strict_mode_fails_only_on_genuine_conflict to verify real conflicts are still detected
  • All existing port allocator tests should continue to pass

Comment thread src/modules/processes.nix Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants