{"record":{"id":"53427216cb2ae624","repo":"libnyanpasu/clash-nyanpasu","slug":"local-socket-too-many-crashes","errorCode":null,"errorMessage":"Local socket too many crashes","messagePattern":"Local socket too many crashes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"backend/tauri-plugin-deep-link/src/windows.rs","lineNumber":76,"sourceCode":"    Ok(())\n}\n\npub fn unregister(schemes: &[&str]) -> Result<()> {\n    for scheme in schemes {\n        let hkcu = RegKey::predef(HKEY_CURRENT_USER);\n        let base = Path::new(\"Software\").join(\"Classes\").join(scheme);\n\n        hkcu.delete_subkey_all(base)?;\n    }\n\n    Ok(())\n}\n\nstatic CRASH_COUNT: AtomicU16 = AtomicU16::new(0);\n\npub fn listen<F: FnMut(String) + Send + 'static>(mut handler: F) -> Result<()> {\n    if CRASH_COUNT.load(Ordering::Acquire) > 5 {\n        panic!(\"Local socket too many crashes\");\n    }\n\n    std::thread::spawn(move || {\n        let name = ID\n            .get()\n            .expect(\"listen() called before prepare()\")\n            .as_str()\n            .to_ns_name::<GenericNamespaced>()\n            .unwrap();\n        tokio::runtime::Builder::new_current_thread()\n            .enable_all()\n            .build()\n            .expect(\"failed to create tokio runtime\")\n            .block_on(async move {\n                let sdsf = \"D:(A;;GA;;;WD)\".to_wtf_16().unwrap();\n                let sd = SecurityDescriptor::deserialize(&sdsf).expect(\"Failed to deserialize SD\");\n                let listener = ListenerOptions::new()\n                    .name(name)","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri-plugin-deep-link/src/windows.rs#L58-L94","documentation":"The deep-link plugin's listen() tracks local-socket listener crashes in a static AtomicU16; once the count exceeds 5 it deliberately panics to avoid an infinite crash-rebind loop on the deep-link local socket.","triggerScenarios":"Calling listen() (directly or via register) when CRASH_COUNT > 5, i.e. after more than five prior listener thread crashes in the same process lifetime.","commonSituations":"Another process holds the deep-link local socket name, repeated bind failures on Windows named pipes, or a handler repeatedly panicking and respawning the listener.","solutions":["Find and close the process holding the deep-link local socket","Restart the application to reset CRASH_COUNT","Fix the recurring listener crash (check handler panics and socket name conflicts) before re-registering"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if deep_link::CRASH_COUNT.load(Ordering::Acquire) > 5 {\n  // abort registration and report degraded state\n  return Err(DeepLinkUnavailable);\n}","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(|| deep_link::listen(handler)) {\n  Ok(res) => res,\n  Err(_) => { log::error!(\"deep-link listener disabled after repeated crashes\"); Err(DeepLinkUnavailable) }\n}","preventionTips":["Ensure only one app instance binds the deep-link socket","Fix handler panics that inflate CRASH_COUNT","Treat panic-on-listen as a fatal startup condition and fail fast"],"tags":["deep-link","local-socket","windows","panic"],"backgroundTag":"address-already-in-use","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}