nodejs/node · error

failed to read input [%s]: %s\n

Error message

failed to read input [%s]: %s\n

What it means

After `fread` to fill the input buffer, `ferror(context->fin)` is set, indicating a read error occurred mid-stream. The operation aborts immediately. The message includes the input path and the errno description. This fires on every chunk read, so it can occur partway through a large file.

Source

Thrown at deps/brotli/c/tools/brotli.c:1093

  context->total_out = 0;
  if (context->verbosity > 0) {
    context->start_time = clock();
  }
}

/* This method might give the false-negative result.
   However, after an empty / incomplete read it should tell the truth. */
static BROTLI_BOOL HasMoreInput(Context* context) {
  return feof(context->fin) ? BROTLI_FALSE : BROTLI_TRUE;
}

static BROTLI_BOOL ProvideInput(Context* context) {
  context->available_in =
      fread(context->input, 1, kFileBufferSize, context->fin);
  context->total_in += context->available_in;
  context->next_in = context->input;
  if (ferror(context->fin)) {
    fprintf(stderr, "failed to read input [%s]: %s\n",
            PrintablePath(context->current_input_path), strerror(errno));
    return BROTLI_FALSE;
  }
  return BROTLI_TRUE;
}

/* Internal: should be used only in Provide-/Flush-Output. */
static BROTLI_BOOL WriteOutput(Context* context) {
  size_t out_size = (size_t)(context->next_out - context->output);
  context->total_out += out_size;
  if (out_size == 0) return BROTLI_TRUE;
  if (context->test_integrity) return BROTLI_TRUE;

  fwrite(context->output, 1, out_size, context->fout);
  if (ferror(context->fout)) {
    fprintf(stderr, "failed to write output [%s]: %s\n",
            PrintablePath(context->current_output_path), strerror(errno));
    return BROTLI_FALSE;

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Verify the input file integrity and accessibility: `dd if=input of=/dev/null bs=1M`.
  2. If reading from a pipe, ensure the upstream process stays alive for the full duration.
  3. Copy the file to a healthy local filesystem and retry.
  4. Check `dmesg` for hardware/driver-level I/O errors.
Defensive patterns

Strategy: validation

Validate before calling

#include <unistd.h>
#include <stdbool.h>

bool input_file_intact(const char *path) {
    // Best-effort: verify read access and that file is not a broken symlink
    if (access(path, R_OK) != 0) return false;
    return true;
}

// For ongoing integrity, compute a checksum before and after processing.

Prevention

When it happens

Trigger: Physical disk read error (EIO); NFS read timeout or server disconnect; file truncated by another process during reading; reading from a pipe whose writer closed early; I/O error on a degraded RAID array.

Common situations: Processing a file on a failing disk; concurrent truncation of the input file by another process; reading from stdin via a pipe where the upstream process crashed; NFS mount instability.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/ed5a71eb4bc9086f. Report an issue: GitHub.