stream-utils / raw-body

Get and validate the raw body of a readable stream

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

x-www-form-urlencoded request resulting in Request Aborted

dmolineuxcb opened this issue · comments

Hi there,

I have probably something not configured correctly, but I have researched and googled this issue for a couple days now and haven't made any head way, any help would be hugely helpful.

When I send an x-www-form-urlencoded request with a couple parameters, the request seems to timeout resulting in the onAborted stream listener to trigger (after a 120 second timeout).

My request is a "POST" that I can send with postman to reproduce.

image

I have added some logging inside node_modules/raw-body/index.js to try to track down whats actually happening inside readStream function.

It appears that none of the listeners are ever triggering (none of these functions are called, except for onAborted):

  // attach listeners
  stream.on("aborted", onAborted);
  stream.on("close", cleanup);
  stream.on("data", onData);
  stream.on("readable", (chunk) => {
    console.log("data can be read", chunk);
  });
  stream.on("end", onEnd);
  stream.on("error", onEnd);

After I send the request, I can only onAborted get triggered, and this is after 120 seconds (on our dev server this is 60 seconds) so I believe this is the result of a timeout triggering.

After logging the stream, I can see that the body is actually being parsed completely and correctly:

  files: null,
  read: [Function],
  body: 
   { bt_signature: 'bn3gnsr7qw534sgt%26cxqbt32bycvftqkp%7Cd3180e35f92dd5e9b772cf330f6076fa5d31d235',
     bt_payload: 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPG5vdGlm%0AaWNhdGlvbj4KICA8a2luZD5jaGVjazwva2luZD4KICA8dGltZXN0YW1wIHR5%0AcGU9ImRhdGV0aW1lIj4yMDE2LTEyLTE0VDE1OjUxOjM1WjwvdGltZXN0YW1w%0APgogIDxzdWJqZWN0PgogICAgPGNoZWNrIHR5cGU9ImJvb2xlYW4iPnRydWU8%0AL2NoZWNrPgogIDwvc3ViamVjdD4KPC9ub3RpZmljYXRpb24%2BCg%3D%3D%0A' },
  _body: true,
  length: undefined }

The readableState of the stream looks like this:

      ReadableState {
        objectMode: false,
        highWaterMark: 16384,
        buffer: [Object],
        length: 0,
        pipes: null,
        pipesCount: 0,
        flowing: true,
        ended: false,
        endEmitted: false,
        reading: true,
        sync: false,
        needReadable: true,
        emittedReadable: false,
        readableListening: false,
        resumeScheduled: false,
        defaultEncoding: 'utf8',
        ranOut: false,
        awaitDrain: 0,
        readingMore: false,
        decoder: null,
        encoding: null },

I've tried a few different versions of Node but all with the same behavior, (v6.2.2 and v7.2.1).

I'm not quite sure what else to try, or what other information I should provide. Do you have any thoughts on why this is happening?

Thank you,
Doug

If you can post the full, complete application code you are using that has the behavior, we can run it and reproduce, attach a debugger and track down the issue. Please include the version of Node.js, the exact version of any used dependencies, and the complete request you are sending, including all headers.

Thank you for the response, I will work on this.

sorry i feel like an idiot, i rebuilt a new server, new tests and everything and narrowed it down to some middle ware we are using called "express-fileupload"

Apparently that adds stuff to a native "stream" object (something called busboy?) I'm not 100% sure why this causes it to fail. But as soon as I remove

const fileUpload = require("express-fileupload");
...
app.use(fileUpload());

The request works, im so glad I fixed it, but sorry to bother you with this.

You probably don't care about it, (ill report to the owner of express-fileupload) but just incase you are interested I reproduced it with this application, you can npm test to make the request fail:

repro_onabort.zip