nodejs/node · error
fclose failed [%s]: %s\n
Error message
fclose failed [%s]: %s\n
What it means
`fclose` on the output file (`context->fout`) returned non-zero. This typically signals that buffered data could not be flushed to disk — the most serious variant because it means the output may be incomplete or corrupt. The message shows the output path and errno string.
Source
Thrown at deps/brotli/c/tools/brotli.c:1033
}
}
static BROTLI_BOOL OpenFiles(Context* context) {
BROTLI_BOOL is_ok = OpenInputFile(context->current_input_path, &context->fin);
if (!context->test_integrity && is_ok) {
is_ok = OpenOutputFile(
context->current_output_path, &context->fout, context->force_overwrite);
}
return is_ok;
}
static BROTLI_BOOL CloseFiles(Context* context, BROTLI_BOOL rm_input,
BROTLI_BOOL rm_output) {
BROTLI_BOOL is_ok = BROTLI_TRUE;
if (!context->test_integrity && context->fout) {
if (fclose(context->fout) != 0) {
if (is_ok) {
fprintf(stderr, "fclose failed [%s]: %s\n",
PrintablePath(context->current_output_path), strerror(errno));
}
is_ok = BROTLI_FALSE;
}
if (rm_output && context->current_output_path) {
unlink(context->current_output_path);
}
/* TOCTOU violation, but otherwise it is impossible to set file times. */
if (!rm_output && is_ok && context->copy_stat) {
CopyStat(context->current_input_path, context->current_output_path);
}
}
if (context->fin) {
if (fclose(context->fin) != 0) {
if (is_ok) {
fprintf(stderr, "fclose failed [%s]: %s\n",View on GitHub (pinned to 1b2de5e052)
Solutions
- Check available disk space: `df -h <output_dir>`.
- If piping to another process, ensure the consumer reads all input before exiting.
- Check user disk quotas: `quota -s`.
- For NFS, verify the mount is healthy and the server is reachable.
- Re-run the compression after freeing space; the input is preserved unless `--rm` was used.
Defensive patterns
Strategy: validation
Validate before calling
#include <sys/statvfs.h>
#include <stdbool.h>
bool output_has_space(const char *path, unsigned long long min_bytes) {
struct statvfs vfs;
if (statvfs(path, &vfs) != 0) return true; // can't check, proceed
unsigned long long avail = (unsigned long long)vfs.f_bavail * vfs.f_bsize;
return avail > min_bytes;
} Prevention
- Check free disk space on the output filesystem before large compressions.
- Avoid piping brotli output to commands like `head` that exit early (causes EPIPE on close).
- Use `--rm` only after verifying the output is complete and valid.
When it happens
Trigger: Disk full (ENOSPC) detected only at flush/close time; write to a broken pipe (EPIPE) if output goes to another process that exited; NFS write commit failure; removable media pulled during write; quota exceeded.
Common situations: Compressing to a nearly-full disk; piping brotli output to `head` or another command that exits early; network filesystem with delayed write errors; user quota limits.
Related errors
- failed to write output [%s]: %s\n
- failed to open input file [%s]: %s\n
- failed to open output file [%s]: %s\n
- failed to open dictionary file [%s]: %s\n
- could not get size of dictionary file [%s]
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/e97b848547bf4206.
Report an issue: GitHub.