close
Skip to content

dietpi-software: SABnzbd: harden config generation#7797

Merged
MichaIng merged 2 commits intoMichaIng:devfrom
DealsBeam:fix-sabnzbd-race-condition
Nov 3, 2025
Merged

dietpi-software: SABnzbd: harden config generation#7797
MichaIng merged 2 commits intoMichaIng:devfrom
DealsBeam:fix-sabnzbd-race-condition

Conversation

@DealsBeam
Copy link
Copy Markdown
Contributor

The script was modifying the sabnzbd.ini file immediately after starting the service, often before the service had finished writing the initial configuration. This resulted in the script's changes being overwritten.

This fix replaces the unreliable 'G_SLEEP 1' with a call to 'Create_Config' that includes 'CREATE_CONFIG_CONTENT=[misc]'. This ensures that the script waits until the '[misc]' section is present in sabnzbd.ini before attempting to modify it, thus resolving the race condition.

@MichaIng MichaIng added this to the v9.19 milestone Nov 1, 2025
@MichaIng
Copy link
Copy Markdown
Owner

MichaIng commented Nov 1, 2025

Many thanks. Can you please rebase your commit onto dev? This would solve also the merge conflict.

@MichaIng MichaIng changed the title Beta v9.18.0 (#7763) dietpi-software: SABnbzd: harden config generation Nov 1, 2025
@MichaIng MichaIng changed the title dietpi-software: SABnbzd: harden config generation dietpi-software: SABnzbd: harden config generation Nov 1, 2025
The script was modifying the sabnzbd.ini file immediately after starting the service, often before the service had finished writing the initial configuration. This resulted in the script's changes being overwritten.

This fix replaces the unreliable 'G_SLEEP 1' with a call to 'Create_Config' that includes 'CREATE_CONFIG_CONTENT=[misc]'. This ensures that the script waits until the '[misc]' section is present in sabnzbd.ini before attempting to modify it, thus resolving the race condition.
@MichaIng MichaIng force-pushed the fix-sabnzbd-race-condition branch from 552e00a to 1428f00 Compare November 3, 2025 12:34
@MichaIng
Copy link
Copy Markdown
Owner

MichaIng commented Nov 3, 2025

Just a note: Create_Config stops the service once the expected file exists and in case the optional content found inside it, and it waits another second after systemctl stop has been called. However, the actual process handles the SIGTERM it gets asynchronously, and by default it can take up to 90 seconds timeout until systemd sends a SIGKILL, if the process is still up. Sadly there is no --block or --wait option to make systemctl stop wait until the process(es) really terminated.

A possible way to achieve the same result is to use systemctl --wait kill right after systemctl stop, which does wait until the process(es) terminated. But the additional signal might interfere with ExecStop= or stop signal of the unit. There are some signals unlikely to be handled after a SIGTERM, but nothing guaranteed. Ugly but safer is a systemctl is-active loop.

Anyway, the asynchronous service termination is unlikely to be the actual issue in this particular SABnzbd case, but that the SIGTERM is coming too early, before the config file has been completed. So the G_SLEEP 1 basically is at the wrong place, and has no effect anymore. So waiting for specific content expected near the end of the file seems the right solution here.

@MichaIng MichaIng merged commit cd28167 into MichaIng:dev Nov 3, 2025
1 check passed
@MichaIng MichaIng mentioned this pull request Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants