alibaba/Sentinel · error · IllegalStateException
Size of file <%s> exceeds the bufSize (%d): %d
Error message
Size of file <%s> exceeds the bufSize (%d): %d
What it means
FileInJarReadableDataSource.readSource() opens the jar entry and checks inputStream.available() against the fixed buffer allocated at construction. If the in-jar file is larger than bufSize, reading it into the single buffer would truncate the config, so it throws IllegalStateException naming the file, buffer size, and actual size.
Source
Thrown at sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileInJarReadableDataSource.java:100
}
AssertUtil.notNull(charset, "charset can't be null");
this.buf = new byte[bufSize];
this.charset = charset;
this.jarName = jarName;
this.fileInJarName = fileInJarName;
initializeJar();
firstLoad();
}
@Override
public String readSource() throws Exception {
if (null == jarEntry) {
// Will throw FileNotFoundException later.
RecordLog.warn(String.format("[FileInJarReadableDataSource] File does not exist: %s", jarFile.getName()));
}
try (InputStream inputStream = jarFile.getInputStream(jarEntry)) {
if (inputStream.available() > buf.length) {
throw new IllegalStateException(String.format("Size of file <%s> exceeds the bufSize (%d): %d",
jarFile.getName(), buf.length, inputStream.available()));
}
int len = inputStream.read(buf);
return new String(buf, 0, len, charset);
}
}
private void firstLoad() {
try {
T newValue = loadConfig();
getProperty().updateValue(newValue);
} catch (Throwable e) {
RecordLog.warn("[FileInJarReadableDataSource] Error when loading config", e);
}
}
@Override
public void close() throws Exception {View on GitHub (pinned to a3f40ba8e9)
Solutions
- Increase bufSize at construction to at least the largest expected file size (bounded by MAX_SIZE).
- Or use the default constructor size (1 MB) which covers most rule files.
- Verify the actual in-jar file size: unzip -l app.jar | grep <fileInJarName> and compare with bufSize in the error message.
Example fix
// before new FileInJarReadableDataSource<>(jar, name, parser, 4096, charset); // rules.json grew past 4KB -> IllegalStateException on readSource // after new FileInJarReadableDataSource<>(jar, name, parser, 1024 * 1024, charset);
Defensive patterns
Strategy: validation
Validate before calling
// Size the buffer from the actual entry before constructing
try (JarFile jf = new JarFile(new File(jarName))) {
int size = (int) jf.getInputStream(jf.getJarEntry(fileInJarName)).available();
bufSize = Math.max(size, 4096);
} // then construct with bufSize (<= MAX_SIZE) Try / catch
try {
return ds.readSource();
} catch (IllegalStateException e) {
if (e.getMessage() != null && e.getMessage().contains("exceeds the bufSize")) {
// rebuild datasource with larger bufSize (file grew in new build)
ds = rebuildWithLargerBuffer();
return ds.readSource();
}
throw e;
} Prevention
- Track the in-jar config file size in CI and alert when it approaches bufSize.
- Default to the 1MB buffer unless memory constraints forbid it.
When it happens
Trigger: readSource()/firstLoad() when the target file inside the jar grew beyond bufSize — typical after a jar rebuild added more rules, while the datasource was constructed with a small explicit bufSize or after fat-jar repackaging.
Common situations: Constructing with a tight bufSize (e.g. 4 KB) that fit at first, then the config file grows in a later release; misjudging available() semantics for compressed jar entries (it can under-report but the check still fires when over).
Related errors
- bufSize must between (0, ${MAX_SIZE}], but ${bufSize} get
- ${filePath} file size=${fileSize}, is bigger than bufSize=${
- Max entry count should be at least 1:
- Interval cannot be less than 1
- Invalid second interval (cannot divide by 60):
AI-assisted analysis of alibaba/Sentinel@a3f40ba8e9 (2026-08-14).
Data as JSON: /api/errors/d7196708c8444727.
Report an issue: GitHub.