koajs / koa-body

koa body parser middleware
MIT License
950 stars 130 forks source link

koa-body hangs after some requests with HTTP2 server #169

Open damianobarbati opened 4 years ago

damianobarbati commented 4 years ago

I have this bug with http2 module, it does not happen with https module. Not sure whether this is related to https://github.com/dlau/koa-body/issues/154.

Node version 12.14.0

To reproduce:

yarn install
node -r esm index.js # start
curl -k https://localhost -d 'ciao=1' # keep firing requests until it hangs

File package.json:

{
  "dependencies": {
    "esm": "^3.2.25",
    "koa": "^2.11.0",
    "koa-body": "^4.1.1"
  }
}

File index.js:

import fs from 'fs';
import http2 from 'http2';
import koa from 'koa';
import body from 'koa-body';

const app = new koa();

app.use(body({ multipart: true, formidable: { maxFileSize: '4mb' } }));

app.use(async ctx => ctx.body = 'ciao');

const HTTPS = 443;

const cert = fs.readFileSync('./ssl/fullchain.pem');
const ca = fs.readFileSync('./ssl/chain.pem');
const key = fs.readFileSync('./ssl/privkey.pem');

http2.createSecureServer({ cert, ca, key }, app.callback()).listen(HTTPS, error => error ? console.error(error) : console.info(`https serving on port ${HTTPS}`));