{"record":{"id":"8ed8296c72a3ff99","repo":"tonhowtf/omniget","slug":"thread","errorCode":null,"errorMessage":"thread: {}","messagePattern":"thread: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/autoclick.rs","lineNumber":188,"sourceCode":"                rng_state ^= rng_state >> 7;\n                rng_state ^= rng_state << 17;\n                let jitter = if opts.jitter_pct > 0 {\n                    let pct = (rng_state % (2 * opts.jitter_pct as u64 + 1)) as f64 - opts.jitter_pct as f64;\n                    1.0 + pct / 100.0\n                } else {\n                    1.0\n                };\n                next += base.mul_f64(jitter.max(0.05));\n                if next < Instant::now() {\n                    next = Instant::now();\n                }\n                sleep_until(next);\n            }\n            RUNNING.store(false, Ordering::SeqCst);\n        })\n        .map_err(|e| {\n            RUNNING.store(false, Ordering::SeqCst);\n            anyhow!(\"thread: {}\", e)\n        })?;\n    Ok(())\n}\n\npub fn stop() {\n    RUNNING.store(false, Ordering::SeqCst);\n}\n\n/// Atalho global: para se estiver rodando, senão começa com as últimas opções.\npub fn toggle() -> anyhow::Result<bool> {\n    if RUNNING.load(Ordering::SeqCst) {\n        stop();\n        return Ok(false);\n    }\n    let opts = last_options()\n        .ok_or_else(|| anyhow!(\"configure e inicie uma vez pela tela antes de usar o atalho\"))?;\n    start(opts)?;\n    Ok(true)","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/autoclick.rs#L170-L206","documentation":"start() spawns the autoclicker worker thread and propagates a failure from thread::Builder::spawn via anyhow!(\"thread: {}\", e). The OS refused to create the thread (typically resource exhaustion), and the library resets RUNNING to false before returning this error.","triggerScenarios":"Calling start() when thread spawn fails — usually std::io::Error from the OS: out of memory, per-process or system thread limit reached (RLIMIT/ulimit), or resource unavailability.","commonSituations":"App leaked many threads so the process hit its thread cap; low-memory environments/containers with tight cgroup limits; extremely low ulimit -u on Linux; running thousands of instances of the tool.","solutions":["Audit the app for leaked threads/loops that spawn per operation without joining or exiting.","Raise the thread limit (ulimit -u on Linux) or process memory allowance in constrained environments.","Handle the error by informing the user the autoclicker couldn't start due to OS resource limits, since RUNNING was already reset.","Consider reusing a single long-lived worker thread controlled by flags instead of spawning per start()."],"exampleFix":"// before\nthread::Builder::new().name(\"autoclick\".into()).spawn(move || { ... })\n    .map_err(|e| { RUNNING.store(false, Ordering::SeqCst); anyhow!(\"thread: {}\", e) })?;\n// after\n// reuse a persistent worker; only fail when spawn truly fails:\nmatch worker_handle() {\n    Some(h) => { h.signal_start(opts); Ok(()) }\n    None => Err(anyhow!(\"sem recursos para iniciar o autoclicker: verifique limites do sistema\")),\n}","handlingStrategy":"try-catch","validationCode":"// heurística: limite de threads do processo\nfn near_thread_limit() -> bool {\n    std::fs::read_to_string(\"/proc/self/status\")\n        .map(|s| s.lines().any(|l| l.starts_with(\"Threads:\")))\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match autoclick::start(opts) {\n    Err(e) if e.to_string().starts_with(\"thread:\") =>\n        show_error(\"SO recusou a criação da thread: verifique memória/limites (ulimit)\"),\n    other => other?,\n}","preventionTips":["Avoid spawning a thread per operation; reuse a single worker.","Monitor thread count in long-running sessions to catch leaks.","Raise ulimit -u / cgroup thread limits in sandboxes.","Handle spawn failure by resetting state and informing the user."],"tags":["rust","threading","os-resources","autoclicker"],"backgroundTag":"thread-spawn-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}