douyinWEB/scripts/_fix_dylive_neko12_sigill.py
2026-09-13 22:10:49 -05:00

119 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Recover dylive neko-12 after SIGILL: free mem, patch chrome flags, restart browser, reopen Studio."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "107.173.30.245"
PASS = "Xiao4669805"
STUDIO = "https://studio.youtube.com/channel/UCfP5vcTQEfrHc13yTmmokQw/livestreaming"
def ssh():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
HOST,
22,
"root",
PASS,
timeout=45,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
return c
def run(c, cmd, t=180):
print(f"\n===== {cmd[:90].replace(chr(10),' ')} =====", flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
out = (o.read() + e.read()).decode("utf-8", "replace")
print(out[-12000:] if len(out) > 12000 else out, flush=True)
return o.channel.recv_exit_status(), out
c = ssh()
# 1) How is browser-launch mounted + drop caches if safe
run(
c,
r"""
set +e
echo '=== mounts ==='
docker inspect douyinweb-neko-12 --format '{{range .Mounts}}{{.Source}} -> {{.Destination}}{{println}}{{end}}' | head -40
echo '=== mem before ==='
free -h | head -3
# drop caches (safe) to help chrome restart
sync; echo 3 > /proc/sys/vm/drop_caches
free -h | head -3
# list heavy processes
ps aux --sort=-rss | head -15
""",
)
# 2) Patch host-side browser-launch if bind-mounted; also patch inside container as fallback
run(
c,
r"""
set -euo pipefail
SRC=''
for p in \
/opt/douyinWEB/backend/neko/browser-launch.sh \
/opt/douyinWEB/neko/browser-launch.sh
do
if [ -f "$p" ]; then SRC="$p"; break; fi
done
echo "SRC=$SRC"
if [ -n "$SRC" ]; then
cp -a "$SRC" "${SRC}.bak-sigill-$(date +%s)"
# Harden js-flags against WASM/AVX512 SIGILL on Studio pages; raise renderer heap a bit
python3 - <<PY
from pathlib import Path
p = Path("$SRC")
text = p.read_text(encoding='utf-8')
old = '--js-flags="--max-old-space-size=192"'
new = '--js-flags="--max-old-space-size=256 --no-wasm-simd --wasm-dynamic-tiering-budget=1000000000"'
if old in text:
text = text.replace(old, new)
print('patched js-flags')
elif '--no-wasm-simd' in text:
print('already has no-wasm-simd')
else:
# insert before --memory-model
needle = ' --memory-model=low'
if needle in text and '--no-wasm-simd' not in text:
text = text.replace(
needle,
' --js-flags="--max-old-space-size=256 --no-wasm-simd" \\\n' + needle,
)
print('inserted js-flags')
else:
print('WARN no patch point')
# merge WebAssemblySimd into the second --disable-features line if present
df = '--disable-features=IsolateOrigins,site-per-process,TranslateUI,BackForwardCache'
df2 = '--disable-features=IsolateOrigins,site-per-process,TranslateUI,BackForwardCache,WebAssemblySimd,WebAssemblyLazyCompilation'
if df in text and 'WebAssemblySimd' not in text:
text = text.replace(df, df2)
print('patched disable-features')
p.write_text(text, encoding='utf-8')
print('wrote', p)
PY
fi
# Also copy into running container path(s)
for dest in /etc/neko/browser-launch.sh /usr/bin/browser-launch.sh /opt/neko/browser-launch.sh; do
docker exec douyinweb-neko-12 sh -c "test -f $dest && echo HAS $dest" 2>/dev/null || true
done
docker exec douyinweb-neko-12 sh -c 'find / -name browser-launch.sh 2>/dev/null | head'
""",
)
c.close()
print("PHASE1_DONE")