Skip to content

fix(watcher): publish sites event + auto-clean non-parked deleted sites#239

Merged
geodro merged 1 commit intomainfrom
fix/stale-site-cleanup
Apr 22, 2026
Merged

fix(watcher): publish sites event + auto-clean non-parked deleted sites#239
geodro merged 1 commit intomainfrom
fix/stale-site-cleanup

Conversation

@geodro
Copy link
Copy Markdown
Owner

@geodro geodro commented Apr 22, 2026

Two gaps observed after rm -rf ~/Lerd/neil on a registered site, reported as "neil still shows in the UI":

1. The fast fsnotify onRemoved path didn't fire. The park watcher's onRemoved callback at cmd/lerd/main.go:483 would have published eventbus.KindSites immediately, but the journal shows no Project deleted: neil line — only the Removing stale site: neil from the 30s periodic sweep 30 seconds later. Likely a Go fsnotify race with inotify's IN_DELETE_SELF / IN_IGNORED ordering on rm -rf; hard to reproduce deterministically. The slow path caught the deletion and updated sites.yaml + nginx — but never published eventbus.KindSites, so the dashboard kept showing neil until a manual refresh.

2. removeStale was gated on parked directories. The check if !underParked { continue } meant manually site_link'd sites outside any park never got cleaned when their directory was deleted. They'd sit in sites.yaml indefinitely, nginx 502'ing on every request.

Fixes

  • 30s ticker now publishes eventbus.KindSites when removeStale reports changes, mirroring the onRemoved fast path. UI gets notified within one sweep interval regardless of which cleanup code path fired.
  • removeStale drops the underParked gate. Every registered non-Ignored site is checked; if its path doesn't exist on disk, it gets the same vhost-remove + sites.yaml-remove treatment. Ignored sites 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.go covers three cases:

  • deleted non-parked site is removed from sites.yaml;
  • live site is preserved;
  • Ignored: true site with a dead path is NOT reaped.

Isolated via HOME / XDG_CONFIG_HOME / XDG_DATA_HOME temp-dir overrides so the tests don't touch the user's real sites.yaml.

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.
@geodro geodro merged commit ffe987f into main Apr 22, 2026
3 checks passed
@geodro geodro deleted the fix/stale-site-cleanup branch April 22, 2026 19:10
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.

1 participant