{"record":{"id":"24734ba32f036c3e","repo":"facebook/flow","slug":"parser-out-of-memory","errorCode":null,"errorMessage":"Parser out of memory","messagePattern":"Parser out of memory","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/flow-parser/oxidized-src/FlowParser.js","lineNumber":228,"sourceCode":"  // non-ambient defaults.\n  const filename =\n    typeof options.sourceFilename === 'string' ? options.sourceFilename : '';\n  const filenameBuffer =\n    filename.length > 0 ? Buffer.from(filename, 'utf8') : null;\n\n  // All wasm allocations live inside a single try/finally so a throw from\n  // any malloc, copyToHeap, or the parse call itself frees everything we\n  // managed to allocate. Earlier versions allocated and partially populated\n  // before entering the try, so a throw from copyToHeap leaked the wasm\n  // address back to the heap.\n  let sourceAddr = 0;\n  let filenameAddr = 0;\n  let filenameLen = 0;\n  let parseResult = 0;\n  try {\n    sourceAddr = FlowParserWASM._malloc(sourceBuffer.length + 1);\n    if (!sourceAddr) {\n      throw new Error('Parser out of memory');\n    }\n    if (filenameBuffer != null) {\n      filenameAddr = FlowParserWASM._malloc(filenameBuffer.length + 1);\n      if (!filenameAddr) {\n        throw new Error('Parser out of memory');\n      }\n      copyToHeap(filenameBuffer, filenameAddr);\n      filenameLen = filenameBuffer.length + 1;\n    }\n    copyToHeap(sourceBuffer, sourceAddr);\n\n    // `enableTypes` mirrors OCaml's `types` option, which defaults to true.\n    // Fixtures opt out via `types: false` to exercise the no-type-grammar\n    // path (e.g. ts_syntax fixtures testing that `as`/`satisfies` are not\n    // parsed when types are disabled).\n    const enableTypes = options.enableTypes === false ? 0 : 1;\n    // `sourceType` is sent to Rust as an integer code:\n    //   0 = unspecified / parser default","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/facebook/flow/blob/5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9/packages/flow-parser/oxidized-src/FlowParser.js#L210-L246","documentation":"The oxidized flow-parser (WASM build) allocates a buffer for the source text with FlowParserWASM._malloc(sourceBuffer.length + 1); a return of 0 means the wasm heap is exhausted and it throws 'Parser out of memory'. Allocation lives inside try/finally so the failed allocation is still cleaned up; the error means the source (or the environment) is too large for the available wasm memory.","triggerScenarios":"parse() on very large files (multi-megabyte, e.g. machine-generated JS/bundles) that exceed the WASM heap; parsing many large files in one process without allowing prior allocations to be freed; constrained environments (low-memory containers, 32-bit limits) shrinking available wasm memory.","commonSituations":"Parsing generated artifacts (bundle output, JSON-to-JS data files, protobuf-generated code) in lint/translation pipelines; running parsers in memory-capped CI containers.","solutions":["Skip or split the oversized file: chunk or trim generated files before parsing.","Retry in a fresh process so wasm heap fragmentation from prior parses is cleared.","Raise the memory available to Node (e.g. --max-old-space-size) or move to a 64-bit, higher-memory environment.","Gate parsing on file size (e.g. skip >5MB) so pipelines degrade gracefully instead of throwing."],"exampleFix":"// before\nconst ast = parse(fs.readFileSync(hugeBundle, 'utf8'));\n\n// after\nconst code = fs.readFileSync(file, 'utf8');\nif (Buffer.byteLength(code) > 5 * 1024 * 1024) throw new SkipError(file);\nconst ast = parse(code);","handlingStrategy":"try-catch","validationCode":"// Gate parsing on input size\nconst MAX_PARSE_BYTES = 5 * 1024 * 1024;\nfunction isParsableSize(code) {\n  return Buffer.byteLength(code, 'utf8') <= MAX_PARSE_BYTES;\n}","typeGuard":null,"tryCatchPattern":"try {\n  ast = parse(code, {flow: 'all'});\n} catch (e) {\n  if (e.message === 'Parser out of memory') {\n    markSkipped(file, 'too large for wasm heap'); // do not retry the same input in-process\n  } else throw e;\n}","preventionTips":["Skip or shard machine-generated giant files before parsing.","Parse large inputs in disposable worker processes so heap state resets.","Treat this error as permanent per input — retrying the same file in the same process will fail again."],"tags":["flow","parser","wasm","out-of-memory","large-files"],"backgroundTag":"wasm-out-of-memory","analyzedSha":"5c865861998a8ccb7dbc82b0c1f511e9ef60c3d9","analyzedAt":"2026-08-20T10:41:37.992Z","contentChangedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}