{"record":{"id":"db47fa58fe9d2021","repo":"clockworklabs/SpacetimeDB","slug":"js-worker-panicked-during-startup","errorCode":null,"errorMessage":"JS worker panicked during startup","messagePattern":"JS worker panicked during startup","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/core/src/host/v8/mod.rs","lineNumber":1650,"sourceCode":"                    Either::Left(module) => (module.replica_ctx(), module.scheduler()),\n                    Either::Right(mcc) => (&mcc.replica_ctx, &mcc.scheduler),\n                };\n                let instance_env = InstanceEnv::new(replica_ctx.clone(), scheduler.clone());\n                scope.set_slot(JsInstanceEnv::new(instance_env));\n\n                let startup_result = panic::catch_unwind(AssertUnwindSafe(|| {\n                    catch_exception(scope, |scope| Ok(builtins::evaluate_builtins(scope)?))\n                        .expect(\"our builtin code shouldn't error\");\n\n                    // Setup the JS module, find call_reducer, and maybe build the module.\n                    startup_instance_worker(scope, program.clone(), generation_module_or_mcc)\n                }));\n\n                let (hooks, module_common) = match startup_result {\n                    Err(_) => {\n                        if let Some(result_tx) = startup_result_tx.take() {\n                            if result_tx\n                                .send(Err(anyhow::anyhow!(\"JS worker panicked during startup\")))\n                                .is_err()\n                            {\n                                log::error!(\"startup result receiver disconnected\");\n                            }\n                        } else {\n                            log::error!(\"JS worker panicked while recreating isolate\");\n                        }\n                        return;\n                    }\n                    Ok(Err(err)) => {\n                        if let Some(result_tx) = startup_result_tx.take() {\n                            if result_tx.send(Err(err)).is_err() {\n                                log::error!(\"startup result receiver disconnected\");\n                            }\n                        } else {\n                            log::error!(\"failed to restart JS worker: {err:#}\");\n                        }\n                        return;","sourceCodeStart":1632,"sourceCodeEnd":1668,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/core/src/host/v8/mod.rs#L1632-L1668","documentation":"The V8 worker thread wraps the whole isolate startup — evaluating builtins and running startup_instance_worker — in panic::catch_unwind. If the Rust side of the worker panics (as opposed to a JS exception, which catch_exception handles and reports differently), the panic is caught and reported to whoever awaits the startup result as this error. The isolate never comes up for this generation; when it happens while recreating an isolate it is logged instead of sent over the channel.","triggerScenarios":"A Rust-level panic in the host's V8 integration during startup: isolate or platform initialization failure, out-of-memory while creating the isolate or compiling builtins, or a bug in the startup path (unwrap on None, index out of bounds) — distinct from user JS errors which surface as JS exceptions.","commonSituations":"Memory-constrained hosts where isolate allocation aborts; v8 platform flags or versions mismatched with the host build; host regressions in builtin evaluation after an upgrade; repeated crashes while recreating isolates for a new module generation.","solutions":["Collect the panic backtrace from host logs (run with RUST_BACKTRACE=1) — this is a host-side failure, not a module error.","Free memory or raise container limits and retry the publish; isolate creation is memory-hungry.","Redeploy on a host build where the V8 startup path is known-good (pin or upgrade the host version).","If it reproduces, minimize the module and report it upstream with the backtrace."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match startup_rx.await {\n    Err(e) if e.to_string().contains(\"panicked during startup\") => {\n        // transient host-side failure: free resources, collect RUST_BACKTRACE=1 logs,\n        // recycle the worker / redeploy with backoff\n        restart_worker_with_backoff().await\n    }\n    other => other,\n}","preventionTips":["Run the host with RUST_BACKTRACE=1 so panics carry a trace in logs.","Size host memory for isolate-creation spikes.","Pin a known-good host version and upgrade deliberately."],"tags":["v8","panic","isolate","startup"],"backgroundTag":"runtime-panic","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}