fix(watcher): publish sites event + auto-clean non-parked deleted sites#239
Merged
fix(watcher): publish sites event + auto-clean non-parked deleted sites#239
Conversation
Two gaps observed when user ran rm -rf ~/Lerd/neil on a registered site:
1. The fast fsnotify onRemoved path (cmd/lerd/main.go:483) didn't fire,
so the UI never got told the site was gone. Could be a Go fsnotify
race with inotify's IN_DELETE_SELF / IN_IGNORED ordering on rm -rf;
hard to reproduce deterministically. The 30s periodic sweep caught
the deletion and removed it from sites.yaml + nginx — but never
published eventbus.KindSites, so the dashboard kept showing neil
until manual refresh.
2. removeStale() gated on whether site.Path's parent matched a
parked_directory. Manually site_link'd sites outside any park
never got cleaned up when their dir was deleted — they'd sit in
sites.yaml indefinitely, nginx 502ing on every request.
Fixes:
- The 30s ticker now publishes eventbus.KindSites whenever removeStale
reports a change, mirroring the onRemoved fast path. The UI gets
notified within one sweep interval of any deletion (park or not).
- removeStale drops the underParked gate. Every registered non-Ignored
site is checked; if its path doesn't exist, it gets the same
vhost-remove + sites.yaml-remove treatment. Ignored sites are still
preserved (user explicitly parked them, sweep mustn't reap).
Interval stays at 30s — deliberately not shortened per user preference
("no shorten of periodicy"). The eventbus push + the wider sweep scope
are what make the slow path feel responsive.
Added cmd/lerd/main_test.go with three cases: deleted non-parked site
gets removed, live site is preserved, ignored site with a dead path
is NOT reaped. Uses an isolated HOME / XDG config tree so tests don't
touch the user's real sites.yaml.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two gaps observed after
rm -rf ~/Lerd/neilon a registered site, reported as "neil still shows in the UI":1. The fast fsnotify
onRemovedpath didn't fire. The park watcher'sonRemovedcallback atcmd/lerd/main.go:483would have publishedeventbus.KindSitesimmediately, but the journal shows noProject deleted: neilline — only theRemoving stale site: neilfrom the 30s periodic sweep 30 seconds later. Likely a Go fsnotify race with inotify'sIN_DELETE_SELF/IN_IGNOREDordering onrm -rf; hard to reproduce deterministically. The slow path caught the deletion and updatedsites.yaml+ nginx — but never publishedeventbus.KindSites, so the dashboard kept showingneiluntil a manual refresh.2.
removeStalewas gated on parked directories. The checkif !underParked { continue }meant manuallysite_link'd sites outside any park never got cleaned when their directory was deleted. They'd sit insites.yamlindefinitely, nginx 502'ing on every request.Fixes
eventbus.KindSiteswhenremoveStalereports changes, mirroring theonRemovedfast path. UI gets notified within one sweep interval regardless of which cleanup code path fired.removeStaledrops theunderParkedgate. Every registered non-Ignoredsite is checked; if its path doesn't exist on disk, it gets the same vhost-remove +sites.yaml-remove treatment.Ignoredsites are still preserved — the user explicitly parked them in that state and the sweep must not reap them.Deliberately unchanged
Interval stays at 30 seconds. Not shortened per user preference ("no shorten of periodicy"). The eventbus push + wider sweep scope are what make the slow path feel responsive; tightening the tick frequency isn't necessary.
Tests
New
cmd/lerd/main_test.gocovers three cases:Ignored: truesite with a dead path is NOT reaped.Isolated via
HOME/XDG_CONFIG_HOME/XDG_DATA_HOMEtemp-dir overrides so the tests don't touch the user's realsites.yaml.