windmill-labs/windmill · error

fclose is not supported

Error message

fclose is not supported

What it means

The `fclose` stub panics: closing a C stream is unimplemented in the WASM libc shim. Since `fopen`/`fdopen` are equally unsupported, there are no real streams to close; the symbol exists only so C code links, and a runtime call aborts the module.

Source

Thrown at backend/parsers/windmill-parser-java/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. Drop the stream lifecycle code from the component compiled into the module — no streams exist in the sandbox.
  2. Fix the earlier open/read path so cleanup that calls fclose is never reached (the real failure is upstream).
  3. Upgrade windmill-parser-java to a version whose components avoid stdio entirely.
  4. Guard fclose behind a non-WASM build flag if you control the source.

Example fix

// before
FILE *f = fopen(path, "r");
if (f) { ...; fclose(f); }

// after: read from memory; no FILE* lifecycle in WASM
const uint8_t *data = get_in_memory_input(&len);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!input || typeof input !== 'string') throw new Error('invalid parser input');

Try / catch

try {
  const result = parse(input);
} catch (e) {
  if (String(e).includes('fclose is not supported')) {
    // usually a cleanup path after an earlier stream failure; surface the root cause
    throw new Error('parser reached stream cleanup; streams are unsupported in WASM');
  }
  throw e;
}

Prevention

When it happens

Trigger: Code in the WASM module calls `fclose(stream)` on any FILE* — typically in cleanup code after (attempted) file reads/writes, or in destructors/finalizers of native components.

Common situations: Cleanup paths in native code that assume streams were opened successfully; error-handling branches that close a stream before unwinding; dependencies with strict open/close discipline.

Related errors


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