Skip to content
This repository was archived by the owner on Aug 20, 2024. It is now read-only.
This repository was archived by the owner on Aug 20, 2024. It is now read-only.

ERR_OUT_OF_RANGE when proxy response is bigger than 4.2GB #56

@tomasvalentaopenbean

Description

@tomasvalentaopenbean

When a file bigger than 4.2GB is served by the proxy following error is thrown:

node:internal/validators:79
      throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value);
      ^

RangeError [ERR_OUT_OF_RANGE]: The value of "length" is out of range. It must be >= 0 && <= 4294967296. Received 5_368_709_120
    at validateOffset (node:buffer:113:3)
    at Function.concat (node:buffer:550:5)
    at IncomingMessage.<anonymous> (/Users/thonda/programovani/WORK/other/my-proxy/node_modules/koa-better-http-proxy/app/steps/sendProxyRequest.js:18:42)
    at IncomingMessage.emit (node:events:539:35)
    at endReadableNT (node:internal/streams/readable:1345:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'ERR_OUT_OF_RANGE'
}

How to reproduce

  1. create a file that's bigger than 4.2GB
    for example using mkfile command on MacOS
mkfile -n 5g testbigfile.csv
  1. create server.js file that will serve the big file
const express = require('express');
const path = require('path');
const app = express();
const port = 3000;
app.get('*', async (req, res) => {
  const options = {
    root: path.join(__dirname)
  };
  const fileName = 'testbigfile.csv';
  res.sendFile(fileName, options, function (err) {
      if (err) {
          console.error(err);
      } else {
          console.log('Sent:', fileName);
      }
  });
});
app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
});
  1. create proxy.js file
var proxy = require('koa-better-http-proxy');
var Koa = require('koa');
var app = new Koa();
app.use(proxy('http://localhost:3000'));
app.listen(4000);
  1. start the servers: node proxy.js and node server.js
  2. issue a GET request to the proxy `http://localhost:4000
    Error is produced by proxy.js

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions