Skip to content

Shared Formidable IncomingForm instance fails on concurrent uploads #44

@robharper

Description

@robharper

Version: 3.0.2

Description: Providing a custom Formidable IncomingForm instance via the IncomingForm option on create causes concurrent uploads to put that instance in a bad state. The concurrent uploads usually fail with the following error message. Any further uploads after this failure will not complete until the connection times out.

  Error: MultipartParser.end(): stream ended unexpectedly: state = START_BOUNDARY
      at MultipartParser.end (/Users/rob/code/influent3/docker-rhel-fail/node_modules/formidable/lib/multipart_parser.js:326:12)
      at IncomingMessage.<anonymous> (/Users/rob/code/influent3/docker-rhel-fail/node_modules/formidable/lib/incoming_form.js:130:30)
      at emitNone (events.js:86:13)
      at IncomingMessage.emit (events.js:188:7)
      at endReadableNT (_stream_readable.js:975:12)
      at _combinedTickCallback (internal/process/next_tick.js:80:11)
      at process._tickCallback (internal/process/next_tick.js:104:9)

My understanding of Formidable is that the IncomingForm instance should not be reused across requests. The problematic lines in koa-better-body appear to be here.

Steps to reproduce:
Use the example code from the Formidable recipe here: https://github.com/tunnckoCore/koa-better-body/tree/master/recipes/formidable

Use the following to get the server into a failed state:

curl -i http://localhost:4290/ -F "foo=@path_to_some_reasonable_sized_file" & curl -i http://localhost:4290/ -F "foo=@path_to_some_reasonable_sized_file"

where path_to_some_reasonable_sized_file should supply something large enough to ensure the uploads are concurrent. In my case it was a file ~ 500kb.

After the above command, any further upload will lock until the connection times out. E.g. use the recipe's example curl:

curl -i http://localhost:4290/ -F "foo=@%s/README.md" -F user=test

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pkg: koa-better-bodyPriority: MediumThis issue may be useful, and needs some attention.Status: AcceptedIt's clear what the subject of the issue is about, and what the resolution should be.Status: AvailableNo one has claimed for resolving this issue. Generally applied to bugs and enhancement issues.Type: BugInconsistencies or issues which will cause an issue or problem for users or implementors.Type: EnhancementMost issues will probably be for additions or changes. Expected that this will result in a PR.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions