mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 07:02:29 +01:00
new-site.sh took `max(port in apps.conf) + 1` and stopped there. The register is
not the only thing listening on that box and never claimed to be — the
handcrafted services on 4001-4004 are excluded by design, and annushka's enquiry
API holds 4030 behind a hand-written vhost precisely so sync-infra will not
regenerate it.
So allocation was walking toward an occupied port. Measured 2026-09-10: highest
registered 4025, three rows added that day, 4030 live. Four sites away.
A port collision does not fail at allocation. It fails later, when the new unit
starts, binds nothing, and the OTHER app is the one that looks broken.
Both directions are now checked, and they are different questions:
the REGISTER owns "claimed" — a port free on the box but claimed here
belongs to something not currently running,
which is why the existing line stays
the BOX owns "occupied" — a port live on the box but absent from the
register is invisible to the register by
construction
`next_free_port` (lib.sh) is pure — the caller passes what is taken — so it is
tested without the box or the network. `listening_ports` does the one ssh sweep.
If the box cannot be reached the sweep returns nothing, which is
indistinguishable from "nothing is listening". That case now says so explicitly
rather than letting an unchecked port print as a checked one.
Live-verified against the box: 38 listeners read, 4030 among them; the real next
allocation (4026) is unchanged, and 4030 correctly advances to 4031.
Verified: port-alloc 6 passed (new, wired into test:ops), apply-schema 34,
uptime-sweep 66, ci-gate 15, launch-template ok, site-template 11,
client-ledger 13, deploy-ready green. lib.sh is sourced widely, so all of it
was re-run rather than assumed.
Claude-Session: https://claude.ai/code/session_01HVudRzEmLqLHvGNqFSpJq6
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
63 lines
2.4 KiB
Bash
Executable File
63 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Tests for next_free_port (scripts/hetzner/lib.sh).
|
|
#
|
|
# THE BUG THIS LOCKS SHUT
|
|
#
|
|
# new-site.sh allocated `max(port in apps.conf) + 1` and nothing else. The
|
|
# register is not the only thing listening on that box and never claimed to be:
|
|
# the handcrafted services on 4001-4004 are excluded by design, and annushka's
|
|
# enquiry API holds 4030 behind a hand-written vhost specifically so sync-infra
|
|
# will not regenerate it. On 2026-09-10 the highest registered port was 4025 and
|
|
# three rows had been added that day, so allocation was four sites from handing
|
|
# out 4030.
|
|
#
|
|
# A port collision does not fail at allocation. It fails later, when the new
|
|
# unit starts, binds nothing, and the OTHER app is the one that looks broken —
|
|
# which is why this is worth a gate rather than a comment.
|
|
#
|
|
# next_free_port is pure (the caller passes what is taken), so every case here
|
|
# runs without the box and without the network.
|
|
#
|
|
# Run: bash scripts/hetzner/test-port-alloc.sh
|
|
|
|
set -uo pipefail
|
|
|
|
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
. "$HERE/lib.sh"
|
|
|
|
PASSED=0
|
|
fail() { echo " ✗ $1" >&2; exit 1; }
|
|
ok() { PASSED=$((PASSED + 1)); echo " ✓ $1"; }
|
|
is() { [ "$1" = "$2" ] || fail "$3 (got '$1', want '$2')"; }
|
|
|
|
echo "port allocation"
|
|
|
|
is "$(next_free_port 4026 "$(printf '4001\n4030\n')")" 4026 \
|
|
"a free candidate is returned unchanged"
|
|
ok "a candidate nothing holds is returned unchanged"
|
|
|
|
# The exact shape that was four sites away.
|
|
is "$(next_free_port 4030 "$(printf '4001\n4002\n4030\n')")" 4031 \
|
|
"must step over an occupied port"
|
|
ok "a candidate that is live but unregistered is stepped over (annushka's 4030)"
|
|
|
|
is "$(next_free_port 4030 "$(printf '4030\n4031\n4032\n')")" 4033 \
|
|
"must keep stepping across a run"
|
|
ok "a run of occupied ports is walked to the first gap"
|
|
|
|
is "$(next_free_port 4026 "")" 4026 \
|
|
"empty taken-list must not hang or mangle the port"
|
|
ok "an empty taken-list returns the candidate (caller announces it as unverified)"
|
|
|
|
# A substring must not count as a hit: 403 is not 4030, and grep without -x
|
|
# would have said it was — silently shifting every future allocation by one.
|
|
is "$(next_free_port 403 "$(printf '4030\n')")" 403 \
|
|
"403 must not match 4030"
|
|
ok "matching is exact — 403 is not a hit for 4030"
|
|
|
|
is "$(next_free_port 4030 "$(printf ' 4030 \n')")" 4030 \
|
|
"a padded entry is not an exact match"
|
|
ok "whitespace-padded entries do not match (sweep output is trimmed upstream)"
|
|
|
|
echo " $PASSED passed"
|