#!/usr/bin/env python3 """Deep-diag dy neko-7 SIGILL; apply jitless + CPU-safe chrome flags; recover Studio.""" from __future__ import annotations import sys import time from pathlib import Path import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST = "108.174.50.68" PASS = "Xiao4669805" LOCAL = Path(__file__).resolve().parents[1] / "backend" / "neko" / "browser-launch.sh" STUDIO = "https://studio.youtube.com/channel/UC6ZbNjX9jg6-AeQrqwday8Q/livestreaming" def connect(retries=8): last = None for i in range(retries): try: 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=180, ) return c except Exception as e: last = e print("ssh_retry", i, e, flush=True) time.sleep(2 + i) raise SystemExit(last) def run(c, cmd, t=300): print("\n=====", cmd[:90].replace("\n", " "), flush=True) _i, o, e = c.exec_command(cmd, timeout=t) out = (o.read() + e.read()).decode("utf-8", "replace") print(out[-14000:] if len(out) > 14000 else out, flush=True) return out c = connect() # 1) diagnose run( c, r""" set +e echo '=== cpu ===' lscpu | egrep 'Model name|Flags|Architecture|Vendor' | head -15 grep -m1 flags /proc/cpuinfo | tr ' ' '\n' | grep -E '^(avx|avx2|avx512|sse4|amx)' | sort -u echo '=== mem ===' free -h | head -3 echo '=== chrome ver / recent traps ===' docker exec douyinweb-neko-7 sh -c 'google-chrome --version 2>/dev/null; chromium --version 2>/dev/null; uname -m' dmesg -T 2>/dev/null | grep -iE 'invalid opcode|SIGILL|oom-kill' | tail -12 echo '=== neko7 mem / tabs ===' docker stats douyinweb-neko-7 --no-stream --format '{{.MemUsage}}' docker exec douyinweb-neko-7 python3 -c ' import json,urllib.request try: tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read()) for t in tabs: if t.get("type")=="page": print((t.get("title") or "")[:50], "|", (t.get("url") or "")[:100]) except Exception as e: print("cdp_err", e) ' """, ) # 2) patch local browser-launch to use --jitless (nuclear V8) + disable more native paths src = LOCAL.read_text(encoding="utf-8") old = '--js-flags="--max-old-space-size=192 --no-wasm-simd --no-turbofan"' new = '--js-flags="--max-old-space-size=192 --jitless --no-wasm-simd"' if old in src: src = src.replace(old, new) elif "--jitless" not in src: src = src.replace( '--js-flags="--max-old-space-size=192 --no-wasm-simd --no-turbofan"', new, ) # also force render_mode legacy path is env; add chrome flag to disable wasm entirely via feature old_df = "--disable-features=IsolateOrigins,site-per-process,TranslateUI,BackForwardCache,WebAssemblySimd,WebAssemblyLazyCompilation,OptimizationGuideModelDownloading,OptimizationHints,PageContentAnnotations,PassageEmbeddings" new_df = old_df + ",WebAssembly,CalculateNativeWinOcclusion,CanvasOopRasterization,Vulkan,UseSkiaRenderer" if old_df in src and ",WebAssembly," not in src.split(old_df)[0] + src.split(old_df)[1][:80]: # careful replace once if new_df not in src: src = src.replace(old_df, new_df, 1) # Add CHROME_WRAPPER-style env note: prepend OPENSSL / clear for process in launch_browser marker = ' echo -800 > /proc/self/oom_score_adj 2>/dev/null || true' inject = ''' # Mask AVX512-ish paths that SIGILL on some colo CPUs / Chrome builds export OPENSSL_ia32cap="~0x200000200000000" export CHROME_FORCE_WAKE_ON_LAN=0 echo -800 > /proc/self/oom_score_adj 2>/dev/null || true''' if "OPENSSL_ia32cap" not in src and marker in src: src = src.replace(marker, inject, 1) LOCAL.write_text(src, encoding="utf-8") assert "--jitless" in LOCAL.read_text(encoding="utf-8") # 3) deploy in-place to mounted inode + recreate neko-7 if needed sftp = c.open_sftp() tmp = "/tmp/browser-launch-jitless.sh" with sftp.file(tmp, "wb") as f: f.write(LOCAL.read_bytes()) sftp.chmod(tmp, 0o755) sftp.close() run( c, rf""" set -euo pipefail export DY_NEKO_NAT1TO1=108.174.50.68 # overwrite ALL browser-launch inodes under neko dir for f in /opt/douyinWEB/backend/neko/browser-launch.sh*; do [ -f "$f" ] || continue case "$f" in *.bak*) ;; esac cat {tmp} > "$f" || true done cat {tmp} > /opt/douyinWEB/backend/neko/browser-launch.sh chmod 755 /opt/douyinWEB/backend/neko/browser-launch.sh # verify visible inside 7 docker exec douyinweb-neko-7 grep -n 'jitless\|OPENSSL_ia32cap\|WebAssembly,' /etc/neko/browser-launch.sh || true if ! docker exec douyinweb-neko-7 grep -q jitless /etc/neko/browser-launch.sh; then echo FORCE_RECREATE # recreate container to remount file cd /opt/douyinWEB/backend set -a; source /etc/douyinweb.env; set +a export DY_NEKO_NAT1TO1=108.174.50.68 ./.venv/bin/python - <<'PY' from app import youtube_neko as yn import subprocess # keep profile; recreate via docker compose labels import json name='douyinweb-neko-7' insp=json.loads(subprocess.check_output(['docker','inspect',name], text=True))[0] labels=insp.get('Config',{{}}).get('Labels') or {{}} wd=labels.get('com.docker.compose.project.working_dir') proj=labels.get('com.docker.compose.project') svc=labels.get('com.docker.compose.service') print('compose', wd, proj, svc) if wd and svc: subprocess.check_call(['docker','compose','-p',proj,'up','-d','--force-recreate','--no-deps',svc], cwd=wd) else: # fallback: stop/rm + ensure start 7 only subprocess.call(['docker','stop',name]) subprocess.call(['docker','rm',name]) print(yn.ensure_capacity(8, start_instances={{7}}, reconcile_running=True)) PY sleep 15 fi docker exec douyinweb-neko-7 grep -n 'jitless\|OPENSSL' /etc/neko/browser-launch.sh docker exec douyinweb-neko-7 supervisorctl restart google-chrome sleep 14 docker exec douyinweb-neko-7 sh -c 'for p in /proc/[0-9]*; do cmd=$(tr "\0" " " < "$p/cmdline" 2>/dev/null) case "$cmd" in *remote-debugging-port=9222*) echo "$cmd" | tr " " "\n" | grep -E "jitless|wasm|js-flags|renderer-process|OPENSSL" ; break ;; esac done' # close all pages then open ONE studio livestreaming docker exec douyinweb-neko-7 python3 -c ' import json,urllib.request,time S="{STUDIO}" for i in range(40): try: urllib.request.urlopen("http://127.0.0.1:9222/json/version",timeout=2).read(); break except Exception: time.sleep(1) else: raise SystemExit("no_devtools") tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read()) for t in tabs: if t.get("type")=="page" and t.get("id"): try: urllib.request.urlopen("http://127.0.0.1:9222/json/close/"+t["id"], timeout=3).read() print("closed", (t.get("url") or "")[:80]) except Exception as e: print("close_err", e) req=urllib.request.Request("http://127.0.0.1:9222/json/new?"+S, method="PUT") print("open", urllib.request.urlopen(req,timeout=20).read()[:100]) # wait and check title not Aw Snap / Cant open for i in range(12): time.sleep(2) tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read()) pages=[t for t in tabs if t.get("type")=="page"] for t in pages: title=(t.get("title") or "") url=(t.get("url") or "") print(f"t{i}", title[:70], "|", url[:100]) bad=any("Snap" in (t.get("title") or "") or "SIGILL" in (t.get("title") or "") or "chrome-error" in (t.get("url") or "") for t in pages) ok=any("studio.youtube.com" in (t.get("url") or "") and "livestreaming" in (t.get("url") or "") and "Snap" not in (t.get("title") or "") for t in pages) if ok and not bad: print("STUDIO_OK") break else: print("STUDIO_STILL_BAD") ' dmesg -T 2>/dev/null | grep -i 'invalid opcode' | tail -3 free -h | head -2 """, ) c.close() print("DONE")