windmill-labs/windmill · error

fclose is not supported

Error message

fclose is not supported

What it means

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.

Source

Thrown at backend/parsers/windmill-parser-csharp/src/wasm_libc.rs:170

#[no_mangle]
pub unsafe extern "C" fn fputs(_s: *const c_void, _file: *mut c_void) -> c_int {
    panic!("fputs is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn fputc(_c: c_int, _file: *mut c_void) -> c_int {
    panic!("fputc is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn fdopen(_fd: c_int, _mode: *const c_void) -> *mut c_void {
    panic!("fdopen is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn fclose(_file: *mut c_void) -> c_int {
    panic!("fclose is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn fwrite(
    _ptr: *const c_void,
    _size: usize,
    _nmemb: usize,
    _stream: *mut c_void,
) -> usize {
    panic!("fwrite is not supported");
}

#[no_mangle]
pub unsafe extern "C" fn vsnprintf(
    _buf: *mut c_char,
    _size: usize,
    _format: *const c_char,
    _args: ...

View on GitHub (pinned to e474e8803c)

Solutions

  1. Remove the open/close lifecycle from code running under WASM (keep streams implicit).
  2. Guard fclose calls behind a target check (cfg not wasm / try non-null).
  3. Implement fclose as a no-op in wasm_libc.rs if the stream lifecycle is otherwise harmless.
  4. Fix upstream code so a failed open never reaches fclose in the WASM build.

Example fix

// before
fclose(fp);
// after
if (!wasm_host()) fclose(fp); // or make fclose a no-op shim
Defensive patterns

Strategy: try-catch

Type guard

function safelyClosesStream(fp) {
  return fp == null || isWasmHost() ? null : fp; // only close real (non-wasm) streams
}

Try / catch

try {
  runInWasmParser(code);
} catch (e) {
  if (String(e?.message ?? e).includes("fclose is not supported")) {
    console.warn("Stream teardown called fclose in wasm; remove open/close lifecycle from wasm paths.");
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Code closes a FILE* obtained from fopen/fdopen inside the WASM runtime; cleanup/teardown paths that unconditionally fclose stdout/stderr.

Common situations: 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.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/d8ec9aa6c382da4c. Report an issue: GitHub.