fix(felhomsshd): keep the persisted port unconditionally (no self-listen flip-flop)

On a continuous reconcile felhom-sshd itself listens on the claimed port, so
re-probing isFree(persisted) found it 'busy' by our own daemon and thrashed to
another candidate every tick. A persisted port is ours — keep it.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PSK5g6qYLknKj8u3QAFEr6
This commit is contained in:
2026-07-05 22:43:22 +02:00
parent d880289b06
commit b99d02b7a9
2 changed files with 14 additions and 15 deletions
+4 -8
View File
@@ -78,10 +78,11 @@ func TestClaimPort_CleanContentionIdempotentExhaustion(t *testing.T) {
t.Fatalf("contention claim = %d / %v, want 2222", p, err)
}
// idempotent: persisted 2222 still free (even though 8822 is now free) → keep 2222 (no thrash)
isFree, read, write, _ = claimHarness(map[int]bool{8822: true, 2222: true, 8022: true, 62222: true}, 2222)
// idempotent: a persisted port is KEPT unconditionally (even when isFree(cur) reports busy —
// that's felhom-sshd itself holding it on a continuous reconcile; re-probing would flip-flop).
isFree, read, write, _ = claimHarness(map[int]bool{8822: true, 2222: false, 8022: true, 62222: true}, 2222)
if p, err := claimPort(cands, isFree, read, write); err != nil || p != 2222 {
t.Fatalf("idempotent claim = %d / %v, want 2222 (kept)", p, err)
t.Fatalf("persisted port must be kept even when isFree says busy (own daemon), got %d / %v", p, err)
}
// exhaustion: all busy → LOUD error, no fallback
@@ -97,9 +98,4 @@ func TestClaimPort_CleanContentionIdempotentExhaustion(t *testing.T) {
t.Fatalf("exhaustion must persist nothing, stored=%d", *stored)
}
// persisted port that is now BUSY → re-claim a fresh free one (not the stale persisted)
isFree, read, write, _ = claimHarness(map[int]bool{8822: false, 2222: true, 8022: true, 62222: true}, 8822)
if p, err := claimPort(cands, isFree, read, write); err != nil || p != 2222 {
t.Fatalf("stale-persisted re-claim = %d / %v, want 2222", p, err)
}
}