nodejs/node · error

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

Error message

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

What it means

`fread` on the dictionary file returned fewer bytes than expected (`bytes_read != context->dictionary_size`). The file was opened and sized successfully, but the actual read was short. The buffer is freed and the dictionary path + errno are reported.

Source

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

  if (file_size_64 > kMaxDictionarySize) {
    fprintf(stderr, "dictionary [%s] is larger than maximum allowed: %d\n",
            PrintablePath(context->dictionary_path), kMaxDictionarySize);
    fclose(f);
    return BROTLI_FALSE;
  }
  context->dictionary_size = (size_t)file_size_64;

  buffer = (uint8_t*)malloc(context->dictionary_size);
  if (!buffer) {
    fprintf(stderr, "could not read dictionary: out of memory\n");
    fclose(f);
    return BROTLI_FALSE;
  }
  bytes_read = fread(buffer, sizeof(uint8_t), context->dictionary_size, f);
  if (bytes_read != context->dictionary_size) {
    free(buffer);
    fprintf(stderr, "failed to read dictionary [%s]: %s\n",
            PrintablePath(context->dictionary_path), strerror(errno));
    fclose(f);
    return BROTLI_FALSE;
  }
  fclose(f);
  context->dictionary = buffer;
  if (command == COMMAND_COMPRESS) {
    context->prepared_dictionary = BrotliEncoderPrepareDictionary(
        BROTLI_SHARED_DICTIONARY_RAW, context->dictionary_size,
        context->dictionary, BROTLI_MAX_QUALITY, NULL, NULL, NULL);
    if (context->prepared_dictionary == NULL) {
      fprintf(stderr, "failed to prepare dictionary [%s]\n",
              PrintablePath(context->dictionary_path));
      return BROTLI_FALSE;
    }
  }
  return BROTLI_TRUE;
}

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Re-read the dictionary file from stable storage.
  2. Ensure no other process is modifying the dictionary file during compression.
  3. Copy the dictionary to a local filesystem (e.g. /tmp) to avoid network I/O issues.
  4. Verify file integrity with `sha256sum` before and after.
Defensive patterns

Strategy: retry

Validate before calling

#include <sys/stat.h>
#include <stdbool.h>

bool dictionary_stable(const char *path, time_t *prev_mtime) {
    struct stat st;
    if (stat(path, &st) != 0) return false;
    if (*prev_mtime != 0 && st.st_mtime != *prev_mtime) return false;
    *prev_mtime = st.st_mtime;
    return true;
}

Prevention

When it happens

Trigger: An I/O error occurred during the read (disk fault, NFS timeout); the file was truncated between `FileSize` and `fread` (race with another process writing/shrinking it); a read interruption on a network-mounted filesystem.

Common situations: Dictionary file being concurrently modified; storage media degradation; NFS mount with intermittent connectivity; file on a FUSE filesystem that returns short reads.

Related errors


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