koajs / koajs/static-cache

[bug] RangeError [ERR_FS_FILE_TOO_LARGE] when buffer set false.

Open
#103 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
291
Forks
48
PR merge metrics
No merged PRs in 30d

Description

## Describe the bug

**Node.js version:** v16.20.1

**OS version:** macOS 13.5.1

**Description:** the app crashes when attempting to read a file larger than 2GB.. setting config.buffer false.

## Actual behavior

a file larger than 2GB located in the /public directory can cause the entire app to crash when attempting to read it.

## Expected behavior

reading it normally.

## Code to reproduce

```javascript
const Koa = require("koa");
const path = require("path");
const staticCache = require("koa-static-cache");
const app = new Koa();

app.use(
staticCache(path.join(__dirname, "public"), {
buffer: false,
dynamic: true,
preload: false,
})
);

app.use(async (ctx) => {
ctx.body = "Hello World";
});

app.listen(3000);
```

## Checklist

- [x] I have searched through GitHub issues for similar issues.
- [x] I have completely read through the README and documentation.
- [x] I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

## Other
I suspect the issue may be related to the loadFile function:

image

Contributor guide

Open the contributing guide

Research direction

Reproduce the crash with the provided Koa example using a file larger than 2GB and buffer:false. Then inspect the loadFile function referenced in the report to trace how large files are read. Done means the example can read the large file without the app crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.