fix(core): skip Electron child processes during hook auto-load
With SNOWLUMA_HOOK_AUTOLOAD=1, the QQ window came up blank — no QR code, login stuck. Cause: the native enumerator (get_all_main_process_ids) returned the main QQ pid plus 2 zygote subprocesses because their cmdline contains "qq" and they transiently inherit wrapper.node via fork copy-on-write. Auto-load fired loadModuleManual for all three, spawning an in-process resolver thread inside each zygote. Renderer processes Electron later forked from those zygotes then inherited those resolver threads + the partially-initialised hook state, which breaks QQ's IPC and prevents the login UI from rendering. Add `shouldAutoLoadPid` which reads /proc/<pid>/cmdline and returns false when it contains `--type=` (Electron child process marker: zygote / renderer / gpu-process / utility). Manual loadProcess() is unaffected — operators picking PIDs from WebUI keep full control. SNOWLUMA_HOOK_AUTOLOAD_ALL=1 disables the filter as an escape hatch. Verified on tempserver: container restart with autoload=1 now shows the QR-code login screen as expected, and only the main qq pid gets the mojo.<pid>.*.sock pair (zygotes stay clean).
This commit is contained in:
2 files changed
+118
-3
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import fs from 'fs';
|
||||
import type { BridgeManager } from '../bridge/manager';
|
||||
import type { PacketSink } from '../protocol/types';
|
||||
import { createLogger, type Logger } from '../utils/logger';
|
||||
@@ -169,7 +170,7 @@ export class HookManager {
|
||||
// injected without a human clicking "Load" in WebUI. Fire-and-forget:
|
||||
// failures are already captured inside loadInternal and surfaced via
|
||||
// the session's status field.
|
||||
if (this.autoLoadOnDiscovery) {
|
||||
if (this.autoLoadOnDiscovery && shouldAutoLoadPid(info.pid, this.log)) {
|
||||
void session.load().catch((err) => {
|
||||
this.log.warn('auto-load failed: PID=%d err=%s', info.pid, errMsg(err));
|
||||
});
|
||||
@@ -243,3 +244,39 @@ function defaultProcessName(): string {
|
||||
function errMsg(value: unknown): string {
|
||||
return value instanceof Error ? value.message : String(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter for auto-load only. Returns false for Linux Electron child
|
||||
* processes (zygote/renderer/gpu/utility), which the native enumerator
|
||||
* mis-classifies as "main QQ" because their cmdline contains "qq" and
|
||||
* they transiently inherit wrapper.node via fork copy-on-write.
|
||||
*
|
||||
* Injecting into a zygote spawns the hook's resolver thread inside it;
|
||||
* every renderer Electron later forks then inherits that thread + the
|
||||
* partially-init'd hook state, which breaks QQ's IPC and login UI.
|
||||
*
|
||||
* Manual loadProcess() bypasses this gate — the operator is responsible
|
||||
* for picking the right PID from WebUI.
|
||||
*/
|
||||
export function shouldAutoLoadPid(pid: number, log: Logger): boolean {
|
||||
if (process.platform !== 'linux') return true;
|
||||
// Escape hatch: operators who explicitly want auto-load on every
|
||||
// enumerated PID can set this to opt out of the filter.
|
||||
if (process.env.SNOWLUMA_HOOK_AUTOLOAD_ALL === '1') return true;
|
||||
|
||||
let cmdline: string;
|
||||
try {
|
||||
cmdline = fs.readFileSync(`/proc/${pid}/cmdline`, 'utf8');
|
||||
} catch {
|
||||
// Can't read cmdline (process gone, permission, etc.) — let the
|
||||
// existing load() path handle it; if the process is dead the load
|
||||
// will fail with a clear error.
|
||||
return true;
|
||||
}
|
||||
if (cmdline.includes('--type=')) {
|
||||
const type = (/--type=([^\0\s]+)/.exec(cmdline)?.[1]) ?? 'unknown';
|
||||
log.info('auto-load skip: PID=%d is an Electron child process (--type=%s)', pid, type);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user