{"record":{"id":"75b36ff37383b6b3","repo":"alibaba/Sentinel","slug":"filepath-file-size-filesize-is-bigger-than","errorCode":null,"errorMessage":"${filePath} file size=${fileSize}, is bigger than bufSize=${bufSize}. Can't read","messagePattern":"(.+?) file size=(.+?), is bigger than bufSize=(.+?)\\. Can't read","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileRefreshableDataSource.java","lineNumber":117,"sourceCode":"            T newValue = loadConfig();\n            getProperty().updateValue(newValue);\n        } catch (Throwable e) {\n            RecordLog.info(\"loadConfig exception\", e);\n        }\n    }\n\n    @Override\n    public String readSource() throws Exception {\n        if (!file.exists()) {\n            // Will throw FileNotFoundException later.\n            RecordLog.warn(String.format(\"[FileRefreshableDataSource] File does not exist: %s\", file.getAbsolutePath()));\n        }\n        FileInputStream inputStream = null;\n        try {\n            inputStream = new FileInputStream(file);\n            FileChannel channel = inputStream.getChannel();\n            if (channel.size() > buf.length) {\n                throw new IllegalStateException(file.getAbsolutePath() + \" file size=\" + channel.size()\n                    + \", is bigger than bufSize=\" + buf.length + \". Can't read\");\n            }\n            int len = inputStream.read(buf);\n            return new String(buf, 0, len, charset);\n        } finally {\n            if (inputStream != null) {\n                try {\n                    inputStream.close();\n                } catch (Exception ignore) {\n                }\n            }\n        }\n    }\n\n    @Override\n    protected boolean isModified() {\n        long curLastModified = file.lastModified();\n        if (curLastModified != this.lastModified) {","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/alibaba/Sentinel/blob/a3f40ba8e900c8489bd520274739f17235a7721c/sentinel-extension/sentinel-datasource-extension/src/main/java/com/alibaba/csp/sentinel/datasource/FileRefreshableDataSource.java#L99-L135","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Shrink the rule file: remove comments/whitespace, split rules across multiple files with one data source each.","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.","Monitor file size against bufSize and alert before the threshold is crossed."],"exampleFix":"// before\nnew FileRefreshableDataSource<>(file, parser, charset); // default buf (1 MB), file grew to 2 MB\n\n// after\nnew FileRefreshableDataSource<>(file, parser, 3000, 4 * 1024 * 1024, charset); // bufSize = 4 MB","handlingStrategy":"validation","validationCode":"// before creating the data source\nint bufSize = (int) Math.min(MAX_ALLOWED, file.length() + slack); // slack for growth, e.g. * 2\nnew FileRefreshableDataSource<>(file, parser, 3000, Math.max(bufSize, DEFAULT_BUF), charset);","typeGuard":null,"tryCatchPattern":"// in a custom wrapper around the data source\ntry {\n    return super.readSource();\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"bigger than bufSize\")) {\n        log.error(\"rule file exceeded bufSize; recreate data source with larger buffer\", e);\n    }\n    throw e;\n}","preventionTips":["Size bufSize to at least 2x the current file size to leave growth headroom.","Keep rule files lean (no comments/minified JSON) or split across multiple files/data sources.","Alert when file size approaches bufSize."],"tags":["sentinel","datasource","file-size","buffer-overflow","java"],"backgroundTag":null,"analyzedSha":"a3f40ba8e900c8489bd520274739f17235a7721c","analyzedAt":"2026-08-14T11:10:30.678Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}