cojs / co-body

Parse request bodies with co
MIT License
325 stars 42 forks source link

update to v5.0.3 breaks my program #55

Closed Chunlin-Li closed 7 years ago

Chunlin-Li commented 7 years ago

After co-body update to v5.0.3, my program can not work as usual. I see a Error below:

 Error
      at IncomingMessage.onEnd (......./node_modules/raw-body/index.js:299:12)
      at emitNone (events.js:91:20)
      at IncomingMessage.emit (events.js:188:7)
      at endReadableNT (_stream_readable.js:974:12)
      at _combinedTickCallback (internal/process/next_tick.js:80:11)
      at process._tickCallback (internal/process/next_tick.js:104:9)

You can reproduce the problem by this script: https://gist.github.com/Chunlin-Li/1f013483dff79f630cf3c92d9c2b1277

The commit of v5.0.3, move the raw(inflate(req), opts); to the Promise chain. this will delay the raw-body execute, and the first onData event will lost. The v5.0.2 works well.

node version: 7.6.2 koa version: 1.4.0 koa-bodyparser version: 2.4.0

dead-horse commented 7 years ago

This is because https://gist.github.com/Chunlin-Li/1f013483dff79f630cf3c92d9c2b1277#file-index-js-L10 listen on data event before raw-body, it isn't a recommended usage, I'll add ctx.request.rawBody to access the raw body later.

Chunlin-Li commented 7 years ago

@dead-horse Thanks for your suggestion! I really need the rawBody access.

dead-horse commented 7 years ago

https://github.com/koajs/bodyparser/commit/d836995468a15347022950c4da9d3222eb7ed2de

lvpro commented 7 years ago

Just wanted to report this broke our commercial app, too (over 100k+ users). We were just using vanilla koa-bodyparser with nothing special. Latest release seems to have fixed the issue.