nsimmons / koa-better-http-proxy

Proxy middleware for Koa. Based on villadora/express-http-proxy
Other
119 stars 42 forks source link

ERR_OUT_OF_RANGE when proxy response is bigger than 4.2GB #56

Open tomasvalentaopenbean opened 1 year ago

tomasvalentaopenbean commented 1 year ago

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

2) 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}`)
});

3) 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);

4) start the servers: node proxy.js and node server.js 5) issue a GET request to the proxy `http://localhost:4000 Error is produced by proxy.js