{"record":{"id":"d8ec9aa6c382da4c","repo":"windmill-labs/windmill","slug":"fclose-is-not-supported","errorCode":null,"errorMessage":"fclose is not supported","messagePattern":"fclose is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-csharp/src/wasm_libc.rs","lineNumber":170,"sourceCode":"\n#[no_mangle]\npub unsafe extern \"C\" fn fputs(_s: *const c_void, _file: *mut c_void) -> c_int {\n    panic!(\"fputs is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fputc(_c: c_int, _file: *mut c_void) -> c_int {\n    panic!(\"fputc is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fdopen(_fd: c_int, _mode: *const c_void) -> *mut c_void {\n    panic!(\"fdopen is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fclose(_file: *mut c_void) -> c_int {\n    panic!(\"fclose is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fwrite(\n    _ptr: *const c_void,\n    _size: usize,\n    _nmemb: usize,\n    _stream: *mut c_void,\n) -> usize {\n    panic!(\"fwrite is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn vsnprintf(\n    _buf: *mut c_char,\n    _size: usize,\n    _format: *const c_char,\n    _args: ...","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-csharp/src/wasm_libc.rs#L152-L188","documentation":"fclose() is stubbed out in wasm_libc.rs and panics with \"fclose is not supported\". Since WASM streams cannot be opened (see fdopen/fwrite stubs), closing a FILE* has no meaning and the shim aborts. Any call to fclose in the WASM runtime is fatal.","triggerScenarios":"Code closes a FILE* obtained from fopen/fdopen inside the WASM runtime; cleanup/teardown paths that unconditionally fclose stdout/stderr.","commonSituations":"atexit/teardown code flushing and closing streams; libraries with a close-on-error path that runs after a partial open attempt; ported C code assuming a POSIX stdio environment.","solutions":["Remove the open/close lifecycle from code running under WASM (keep streams implicit).","Guard fclose calls behind a target check (cfg not wasm / try non-null).","Implement fclose as a no-op in wasm_libc.rs if the stream lifecycle is otherwise harmless.","Fix upstream code so a failed open never reaches fclose in the WASM build."],"exampleFix":"// before\nfclose(fp);\n// after\nif (!wasm_host()) fclose(fp); // or make fclose a no-op shim","handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function safelyClosesStream(fp) {\n  return fp == null || isWasmHost() ? null : fp; // only close real (non-wasm) streams\n}","tryCatchPattern":"try {\n  runInWasmParser(code);\n} catch (e) {\n  if (String(e?.message ?? e).includes(\"fclose is not supported\")) {\n    console.warn(\"Stream teardown called fclose in wasm; remove open/close lifecycle from wasm paths.\");\n  } else {\n    throw e;\n  }\n}","preventionTips":["Do not open/close FILE streams in wasm-targeted code.","Guard cleanup paths so a failed open never reaches fclose under wasm.","Make fclose a no-op shim if the lifecycle is otherwise harmless.","Prefer implicit streams (console) over explicit open/close in wasm."],"tags":["wasm","libc","csharp","file-io","unsupported-symbol"],"backgroundTag":"unsupported-wasm-libc-symbol","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}