{"record":{"id":"0e6f591594d0ce71","repo":"schollz/croc","slug":"croc-wasm-did-not-initialize","errorCode":null,"errorMessage":"croc WASM did not initialize","messagePattern":"croc WASM did not initialize","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/public/croc-worker.js","lineNumber":21,"sourceCode":"let ready;\n\nfunction initialize() {\n  if (ready) return ready;\n  ready = (async () => {\n    importScripts(new URL(\"./wasm_exec.js\", self.location.href).href);\n    const go = new Go();\n    const response = await fetch(new URL(\"./croc.wasm\", self.location.href));\n    if (!response.ok) {\n      throw new Error(`Could not load croc.wasm (${response.status})`);\n    }\n    const bytes = await response.arrayBuffer();\n    const { instance } = await WebAssembly.instantiate(bytes, go.importObject);\n    void go.run(instance);\n    for (let attempts = 0; !self.crocWasm && attempts < 100; attempts += 1) {\n      await new Promise((resolve) => setTimeout(resolve, 10));\n    }\n    if (!self.crocWasm) {\n      throw new Error(\"croc WASM did not initialize\");\n    }\n  })();\n  return ready;\n}\n\nfunction transferables(value, output = []) {\n  if (value instanceof Uint8Array) {\n    output.push(value.buffer);\n  } else if (value && typeof value === \"object\") {\n    for (const child of Object.values(value)) transferables(child, output);\n  }\n  return output;\n}\n\nself.addEventListener(\"message\", async (event) => {\n  const { id, method, args = [] } = event.data;\n  try {\n    await initialize();","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/schollz/croc/blob/e25f1bdc04f07f094d50b0a1bf67e2563944b57a/web/public/croc-worker.js#L3-L39","documentation":"The worker instantiated the Go wasm module and called go.run(instance), then polled self.crocWasm for up to 1000ms (100 attempts x 10ms). If the Go runtime never registers the global crocWasm object within that window, initialization is declared failed. This is a readiness-timeout, not proof the wasm is broken: slow devices, main-thread contention, or a panic inside Go's init path can all exceed the 1-second budget.","triggerScenarios":"Running on low-powered hardware or under heavy CPU throttling where Go's runtime startup plus package init takes longer than 1s; a Go-side panic during initialization that silently prevents crocWasm from being set; wasm_exec.js version mismatch with the compiled croc.wasm so go.run never completes.","commonSituations":"First load on mobile browsers with cold caches; CI headless-browser tests under CPU throttling; rebuilding croc.wasm with a different Go version without updating wasm_exec.js.","solutions":["Reproduce with devtools: check the worker console for a Go panic that explains why crocWasm was never registered","Regenerate croc.wasm and wasm_exec.js from the same Go toolchain so their ABI matches","If startup is just slow, raise the poll budget (more attempts or longer interval) before giving up","Reload the page / recreate the worker to rule out a one-off scheduling stall"],"exampleFix":"// before (croc-worker.js)\nfor (let attempts = 0; !self.crocWasm && attempts < 100; attempts += 1) {\n  await new Promise((resolve) => setTimeout(resolve, 10));\n}\n\n// after: allow up to ~15s for slow devices\nfor (let attempts = 0; !self.crocWasm && attempts < 1500; attempts += 1) {\n  await new Promise((resolve) => setTimeout(resolve, 10));\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Worker startup: terminate and respawn the worker once on init timeout\ntry {\n  await rpc.call(\"ping\");\n} catch (e) {\n  if (e.message === \"croc WASM did not initialize\" && !retriedOnce) {\n    worker.terminate();\n    spawnWorker();\n    retriedOnce = true;\n    return retry();\n  }\n  throw e;\n}","preventionTips":["Rebuild croc.wasm and wasm_exec.js from the same Go version","Keep the poll budget generous (slow devices) — e.g. several seconds, not 1s","Watch the worker console for Go panics during init; treat those as build bugs, not timeouts"],"tags":["wasm","initialization","timeout","web-worker"],"backgroundTag":null,"analyzedSha":"e25f1bdc04f07f094d50b0a1bf67e2563944b57a","analyzedAt":"2026-08-15T12:53:39.096Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}