site serve: report a port that something else holds as taken, and start nothing #252
Labels
No labels
blocked
bug
decision
duplicate
enhancement
help wanted
invalid
landed?
question
ready-to-merge
stale
wontfix
bug
duplicate
enhancement
help wanted
invalid
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
allod/tools#252
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Make
allod site serverefuse to start a preview on a port that something else already holds, so it never prints another program's address as the site's own.Primary goals:
serveexits 1, names the port, and starts nothing.preview_port, or on--port, and on nothing else. A site with neither is refused as it is today.--stopandvieware untouched.Current state
Observed on a dev VM, with another process listening on the site's port before the start, for three apps (zola, live-server, Vite with
--strictPort):The unit's journal for the same start, live-server's case:
Each app failed as its contract requires.
servehad already returned:sitePreviewWait(cmd/allod/site_serve.go:201, atef380c8) takes a connection to the port as good news while the unit is up, and the unit is still up whilenix runis evaluating, before the app has tried to bind. The address printed is the other process's.docs/allod-site-preview.md:10describes this case as reported "as serving".Default
Before starting a unit that is not running (
cmd/allod/site_serve.go:114),serveconnects to the port once. An answer means the port is taken: exit 1, a message naming the port and the unit that was not started, and nosystemd-run. The check comes after the checks of the checkout path and the flake'spreviewapp, so a fault in the site is reported before a port that is only busy for now.A unit that is already running is not checked: finding the site's own preview up is the ordinary case and still prints its address.
What this leaves open
Another process can take the port in the seconds between the check and the app's bind, while
nix runevaluates.servewould then print the address with exit 0 while the unit's journal shows the app failing. With a port the owner assigned in the registry, which nothing else is aiming for, this is rare. Closing it means confirming that the listening socket belongs to a process of the unit, which was built and measured under allod/tools#249 and costs about a hundred lines that read kernel files. It is a follow-up only if the case is seen in use.Validation
--port: exit 1, the port named, no address printed, no unit started.--port, on a free port: started with the samesystemd-runarguments as before.servewhile the preview is running: the address, exit 0.Scope
In: the check before a start in
serve, its message, its tests, the contract bullet indocs/allod-site-preview.md, and the exit-code line ofserve --help. Out: picking a port for a site that has none, andviewlearning a port from the VM, both dropped with allod/tools#249; which registry a dev VM reads, allod/archetypes#119.