Skip to content

fix *arr rootfolders oneshot racing app startup - #286

Merged
kiriwalawren merged 1 commit into
kiriwalawren:mainfrom
jadeezomg:fix/rootfolders-wait-for-api
Aug 1, 2026
Merged

fix *arr rootfolders oneshot racing app startup#286
kiriwalawren merged 1 commit into
kiriwalawren:mainfrom
jadeezomg:fix/rootfolders-wait-for-api

Conversation

@jadeezomg

Copy link
Copy Markdown
Contributor

Hey, ran into a problem where I changed my mounts and the service came up before the mounts did. Noticed ´mkWaitForApiScript´ already exists, just isn't used for the root folders.

Disclaimer: change was assisted by LLM. Full report/testing below

Report

<serviceName>-rootfolders is the only API reconciler that adds nixflix.serviceDependencies to its after/requires, so a remount of one of those mounts propagates a restart to it while <serviceName>.service is still coming back up. <serviceName>-config.service is RemainAfterExit=true and doesn't require those deps, so the wait-for-api it owns doesn't re-run — the reconciler's first curl -Sf $BASE_URL/rootfolder hits a closed port and set -e kills the oneshot with exit 7.

Hit on an NFS-backed host: sonarr-rootfolders started at 17:19:00 while sonarr.service only reached active at 17:19:02, with sonarr-config.service untouched since Jul 25. Fix reuses the ExecStartPre already on <serviceName>-config.service. Added VM test step fails on main with status=7/NOTRUNNING and passes with the fix.

Testing

Local nix build .#checks.x86_64-linux.<check> on x86_64-linux, flake.lock unchanged:
full-stack, sonarr-basic, radarr-basic, lidarr-basic, sonarr-anime-basic,
unit-tests, formatting — all pass.

With modules/arr-common/rootFolders.nix reverted to main and the new full-stack step
kept, the test fails with the reported signature:

[48.857626] sonarr-rootfolders.service: Main process exited, code=exited, status=7/NOTRUNNING
!!! RequestedAssertionFailed: command `systemctl restart --no-block sonarr.service;
    systemctl restart sonarr-rootfolders.service` failed (exit code 1)

With the fix, all four *arr services reconcile after a restart racing app startup:

sonarr root folders reconciled after a restart racing app startup!
sonarr-anime root folders reconciled after a restart racing app startup!
radarr root folders reconciled after a restart racing app startup!
lidarr root folders reconciled after a restart racing app startup!

Not run locally: jellyfin/prowlarr/seerr/maintainerr/qbittorrent/sabnzbd/recyclarr basics,
the caddy/nginx/postgresql/vpn integration tests, docs-build — none instantiate
rootFolders.nix.

<serviceName>-rootfolders is the only API reconciler that adds
nixflix.serviceDependencies to its after/requires, so it can be restarted
independently of <serviceName>-config.service — for example when one of those
mounts is remounted, which propagates a restart to every unit requiring it.

<serviceName>-config.service is Type=oneshot RemainAfterExit=true and does not
require serviceDependencies, so in that case the wait-for-api it owns does not
re-run and nothing waits for the app: the reconciler's first
`curl -Sf $BASE_URL/rootfolder` hits a closed port and set -e kills the oneshot
with curl's exit 7, which systemd reports as 7/NOTRUNNING. The root folders are
then never reconciled, and the failed unit is left for the next activation.

Gate the unit on the API itself with the same ExecStartPre already used by
<serviceName>-config.service, and cover the race in the full-stack VM test by
restarting each *arr service together with its rootfolders reconciler.
@kiriwalawren

Copy link
Copy Markdown
Owner

Good catch! Thank you so much for the PR!

@jadeezomg

Copy link
Copy Markdown
Contributor Author

thank you for this sweet flake!

@kiriwalawren
kiriwalawren merged commit 68d059f into kiriwalawren:main Aug 1, 2026
39 of 40 checks passed
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.

2 participants