honojs / node-server

Node.js Server for Hono
https://hono.dev
389 stars 48 forks source link

RangeError [ERR_OUT_OF_RANGE]: The value of "start" is out of range. It must be an integer. Received NaN #190

Open natew opened 2 months ago

natew commented 2 months ago

Seeing this error suddenly but no idea where it's coming from, hard for me to replicate as it's only in production on a decent sized stack, I've upgraded to latest versions "hono": "^4.5.8", and "@hono/node-server": "^1.12.1",:

RangeError [ERR_OUT_OF_RANGE]: The value of "start" is out of range. It must be an integer. Received NaN

at ReadStream (node:internal/fs/streams:206:5)

at createReadStream (node:fs:3079:10)

at file:///app/node_modules/@hono/node-server/dist/serve-static.mjs:89:20

at file:///app/node_modules/vxrn/dist/exports/createServer.mjs:10:7

at dispatch (file:///app/node_modules/hono/dist/compose.js:29:23)

at file:///app/node_modules/hono/dist/compose.js:30:20

at compress2 (file:///app/node_modules/hono/dist/middleware/compress/index.js:5:11)

at dispatch (file:///app/node_modules/hono/dist/compose.js:29:23)

at file:///app/node_modules/hono/dist/compose.js:6:12

at file:///app/node_modules/hono/dist/hono-base.js:200:31

at Hono.dispatch (file:///app/node_modules/hono/dist/hono-base.js:210:7)

at fetch (file:///app/node_modules/hono/dist/hono-base.js:213:17)

at Server.<anonymous> (file:///app/node_modules/@hono/node-server/dist/index.mjs:407:13)
Jayllyz commented 2 months ago

Can you provide a reproduction repository?

natew commented 1 month ago

The only way I've been able to reproduce is in production with the tamagui.dev site. But that requires a lot of setup unfortunately.

I am now on hono 4.6.1 and the stack trace changed just a bit:

CleanShot 2024-09-24 at 10 17 56@2x

I'll check more into those file lines and see if I can figure out why this may be happening so I can setup a smaller repro.

natew commented 1 month ago

Added a patch so right before the line:

const chunksize = end - start + 1;

I added a log:

if (isNaN(start) || isNaN(end)) console.log('nan start or end', start, end, range, parts)

And I can see it logging:

nan start or end NaN 22 bytes: 0-22 [ 'bytes: 0', '22' ]

Looks like the range you're getting here:

const range = c.req.header("range") || "";
    if (!range) {
      c.header("Content-Length", size.toString());
      return c.body(createStreamBody(createReadStream(path)), 200);
    }
    c.header("Accept-Ranges", "bytes");
    c.header("Date", stats.birthtime.toUTCString());
    const parts = range.replace(/bytes=/, "").split("-", 2);

Is expected to be bytes= but instead its bytes: 0-22

yusukebe commented 1 month ago

Hi @natew

Thank you for the issue and your consideration.

I'll check more into those file lines and see if I can figure out why this may be happening so I can setup a smaller repro.

Have you already got a smaller repo?