Skip to content

fix(adblock): resolve race condition on rapid DNS domain changes#1663

Draft
gsanchietti wants to merge 1 commit into
NethServer:mainfrom
gsanchietti:issue1572
Draft

fix(adblock): resolve race condition on rapid DNS domain changes#1663
gsanchietti wants to merge 1 commit into
NethServer:mainfrom
gsanchietti:issue1572

Conversation

@gsanchietti
Copy link
Copy Markdown
Member

Summary

Store whitelist/blacklist in UCI instead of direct file writes. When multiple rapid API calls add/edit/delete domains, changes are staged to UCI (no restart). The init.d script reads UCI during start/reload and writes physical files.

procd's reload trigger (5s debounce) coalesces rapid UCI commits into a single reload_service call. Using reload (not restart) prevents file clearing that caused 'running with 0 blocked domains' broken state.

Related issue

#1572

How to test

  1. ssh root@192.168.100.215
  2. Add multiple domains rapidly: api-cli ns.threatshield dns-add-allowed --data '{"address":"test1.com","description":""}' &
  3. Check UCI staged (should show all entries): api-cli ns.threatshield dns-list-allowed
  4. Apply from UI (or uci commit && reload_config from shell)
  5. Wait 5-6s for procd reload
  6. Verify whitelist file written and adblock status shows enabled (not broken 'running/0')

Files changed

  • ns.threatshield: dns_get_local_list() reads from UCI; dns_write_local_list() writes to UCI + save
  • adblock.init: f_write_local_lists() writes UCI lists to physical files during start/reload
  • 99_adblock_migrate_lists.sh: one-time migration of existing files to UCI (new)
  • Makefile: install migration script

Store whitelist/blacklist in UCI instead of direct file writes. When multiple
rapid API calls add/edit/delete domains, the API now only stages changes to
UCI (no restart). The init.d script calls f_write_local_lists() during
start_service() and reload_service() to write files from UCI.

procd's existing reload trigger (PROCD_RELOAD_DELAY=5s) debounces rapid UCI
commits into a single reload_service call. The reload action (not restart)
prevents f_rmdns (file clearing) that was causing "running with 0 blocked
domains" broken state during concurrent restarts.

Changes:
- ns.threatshield: dns_get_local_list() reads from UCI; dns_write_local_list()
  writes to UCI + save (no commit/restart)
- adblock.init: f_write_local_lists() writes UCI lists to physical files
  during service start/reload
- 99_adblock_migrate_lists.sh: one-time migration of existing files to UCI
- Makefile: install migration script to /etc/uci-defaults/

Closes NethServer#1572

Assisted-by: Copilot:claude-haiku-4.5
@gsanchietti gsanchietti self-assigned this May 13, 2026
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