fix: eliminate reconcile fork-storm (OOM) + resolve UCI config conflict with xray-core
build / aarch64_cortex-a53 (push) Successful in 3m0s
build / x86_64 (push) Successful in 2m59s

Two release-blocking defects found via live 512M OpenWrt VM testing.

1) Fork-storm / OOM (critical). Reconcile() -> reloadXray() ->
   "/etc/init.d/shater reload" -> reload_service -> shater_reconcile ->
   `xrayctl reconcile` -> Reconcile() was an infinite mutual recursion; each
   level blocked on CombinedOutput and spawned a process (854x reconcile +
   853x reload observed), exhausting RAM and pinning both vCPUs -> OOM-killer.
   - Reconcile() no longer calls reloadXray(); procd's file-watch on run.json
     restarts xray. Reconcile runs inside the init lifecycle, so calling the
     init back is the recursion.
   - reloadXray() now runs `/etc/init.d/shater start` (not `reload`); it is only
     invoked from Apply()/Rollback() (LuCI/ubus/CLI), never the init lifecycle.
   - init reload_service() simplified to start/stop (dropped the double reconcile).
   Verified: `xrayctl apply` 0.39s (was >185s hang); 93 procs / load 0.00 stable
   with an active 254-node config on 512M; xray binds :10853 API + :12345 tproxy.

2) UCI config namespace clash. shater shipped /etc/config/xray, which collides
   with the xray-core dependency's own /etc/config/xray (opkg dropped ours to
   /etc/config/xray-opkg, so the schema never took effect). Renamed the UCI
   namespace xray -> shater everywhere (Go uci export/commit, all 11 LuCI views +
   acl, init scripts, hotplug, Makefile conffiles, examples). Runtime paths
   (/etc/xray/run.json, /usr/share/xray), the xray-core package, and the ubus
   object name are intentionally unchanged.

Also: ci/pack-xrayctl.sh (local ipk packer) with a postinst chmod so the binary
is executable regardless of host-tar mode handling; PKG_RELEASE bumped to r3.

Verified end-to-end on a fresh 512M OpenWrt 24.10.3 VM: feed install
(opkg install luci-app-shater pulls xrayctl+shater-core), real LAN client
(netns in br-lan) proxied through a live subscription node -> exit IP changed
(104.156.233.234 vs 45.131.214.140 direct); per-client nft counters + xray
stats API populated. See PROOFS.md.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
omarandClaude Opus 4.8 committed 2026-07-09 11:36:48 +03:00
1 parent 71a6f127a1
commit 05920f83ad
37 files changed
+259 -103

No files matched your search

+11 -11
View File
@@ -35,7 +35,7 @@ DEFAULT_RS_INTERVAL=24h
shater_enabled() {
local en
en=$(uci -q get xray.globals.enabled) || return 1
en=$(uci -q get shater.globals.enabled) || return 1
[ "$en" = "1" ]
}
@@ -74,12 +74,12 @@ shater_run_due() {
# Subscriptions.
i=0
while uci -q get "xray.@subscription[$i]" >/dev/null 2>&1; do
name=$(uci -q get "xray.@subscription[$i].name")
en=$(uci -q get "xray.@subscription[$i].enabled")
while uci -q get "shater.@subscription[$i]" >/dev/null 2>&1; do
name=$(uci -q get "shater.@subscription[$i].name")
en=$(uci -q get "shater.@subscription[$i].enabled")
[ -z "$en" ] && en=1
if [ -n "$name" ] && [ "$en" = "1" ]; then
ivl=$(uci -q get "xray.@subscription[$i].update_interval")
ivl=$(uci -q get "shater.@subscription[$i].update_interval")
secs=$(shater_ivl_secs "$ivl" "$DEFAULT_SUB_INTERVAL")
stamp="$STAMP_DIR/sub.$name"
if shater_due "$stamp" "$secs"; then
@@ -93,11 +93,11 @@ shater_run_due() {
# Rulesets (only url sources auto-update; others have nothing to fetch).
i=0
while uci -q get "xray.@ruleset[$i]" >/dev/null 2>&1; do
name=$(uci -q get "xray.@ruleset[$i].name")
src=$(uci -q get "xray.@ruleset[$i].source")
while uci -q get "shater.@ruleset[$i]" >/dev/null 2>&1; do
name=$(uci -q get "shater.@ruleset[$i].name")
src=$(uci -q get "shater.@ruleset[$i].source")
if [ -n "$name" ] && [ "$src" = "url" ]; then
ivl=$(uci -q get "xray.@ruleset[$i].update_interval")
ivl=$(uci -q get "shater.@ruleset[$i].update_interval")
secs=$(shater_ivl_secs "$ivl" "$DEFAULT_RS_INTERVAL")
stamp="$STAMP_DIR/rs.$name"
if shater_due "$stamp" "$secs"; then
@@ -135,7 +135,7 @@ start_service() {
# Re-exec ourselves as the loop body so procd supervises a single process.
procd_set_param command /bin/sh "$INIT_SCRIPT" loop
procd_set_param respawn 3600 10 0 # threshold timeout always-retry
procd_set_param file /etc/config/xray # restart the loop when UCI changes
procd_set_param file /etc/config/shater # restart the loop when UCI changes
procd_set_param stdout 1
procd_set_param stderr 1
procd_close_instance
@@ -149,5 +149,5 @@ reload_service() {
}
service_triggers() {
procd_add_reload_trigger "xray"
procd_add_reload_trigger "shater"
}