alibaba/Sentinel · error · IllegalStateException

${filePath} file size=${fileSize}, is bigger than bufSize=${

Error message

${filePath} file size=${fileSize}, is bigger than bufSize=${bufSize}. Can't read

What it means

Thrown from FileRefreshableDataSource.readSource() when the polled file's current size exceeds the data source's internal read buffer (bufSize, set at construction and capped at MAX_SIZE). The implementation reads the whole file into one pre-allocated byte[], so a file larger than the buffer cannot be loaded. Because readSource runs on the background refresh timer, this exception surfaces in the refresh loop and via RecordLog rather than at construction time.

Source

Thrown at sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileRefreshableDataSource.java:117

            T newValue = loadConfig();
            getProperty().updateValue(newValue);
        } catch (Throwable e) {
            RecordLog.info("loadConfig exception", e);
        }
    }

    @Override
    public String readSource() throws Exception {
        if (!file.exists()) {
            // Will throw FileNotFoundException later.
            RecordLog.warn(String.format("[FileRefreshableDataSource] File does not exist: %s", file.getAbsolutePath()));
        }
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream(file);
            FileChannel channel = inputStream.getChannel();
            if (channel.size() > buf.length) {
                throw new IllegalStateException(file.getAbsolutePath() + " file size=" + channel.size()
                    + ", is bigger than bufSize=" + buf.length + ". Can't read");
            }
            int len = inputStream.read(buf);
            return new String(buf, 0, len, charset);
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (Exception ignore) {
                }
            }
        }
    }

    @Override
    protected boolean isModified() {
        long curLastModified = file.lastModified();
        if (curLastModified != this.lastModified) {

View on GitHub (pinned to a3f40ba8e9)

Solutions

  1. Re-create the data source with a larger bufSize using the 5-arg constructor: new FileRefreshableDataSource(file, parser, refreshMs, bufSize, charset) with bufSize >= file size (must stay <= MAX_SIZE).
  2. Shrink the rule file: remove comments/whitespace, split rules across multiple files with one data source each.
  3. If the file already exceeds MAX_SIZE, switch to a different data source (e.g. Nacos/Apollo/Zookeeper) that streams configs instead of buffering whole files.
  4. Monitor file size against bufSize and alert before the threshold is crossed.

Example fix

// before
new FileRefreshableDataSource<>(file, parser, charset); // default buf (1 MB), file grew to 2 MB

// after
new FileRefreshableDataSource<>(file, parser, 3000, 4 * 1024 * 1024, charset); // bufSize = 4 MB
Defensive patterns

Strategy: validation

Validate before calling

// before creating the data source
int bufSize = (int) Math.min(MAX_ALLOWED, file.length() + slack); // slack for growth, e.g. * 2
new FileRefreshableDataSource<>(file, parser, 3000, Math.max(bufSize, DEFAULT_BUF), charset);

Try / catch

// in a custom wrapper around the data source
try {
    return super.readSource();
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().contains("bigger than bufSize")) {
        log.error("rule file exceeded bufSize; recreate data source with larger buffer", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: Constructing with the default buffer (or a small custom bufSize) and then the rule file growing past it — e.g. a 2 MB flow-rule.json against the default 1 MB buffer; someone appending many rules or embedding comments/JWT-like blobs in the config file.

Common situations: Rules file grows organically as teams add flow/degrade rules until it crosses the buffer size; operators pretty-print or comment the JSON heavily, inflating size; a large file works in dev but a different, bigger file is deployed in production.

Related errors


AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14). Data as JSON: /api/errors/75b36ff37383b6b3. Report an issue: GitHub.