Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
natew opened this issue Aug 24, 2024 · 4 comments

Comments

@natew
Copy link

natew commented Aug 24, 2024

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
Copy link
Contributor

Jayllyz commented Aug 30, 2024

Can you provide a reproduction repository?

@natew
Copy link
Author

natew commented Sep 24, 2024

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
Copy link
Author

natew commented Sep 28, 2024

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
Copy link
Member

yusukebe commented Oct 6, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants