Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning: Error: Unexpected end of form #10264

Closed
4 of 15 tasks
Mateozmaldonado17 opened this issue Sep 10, 2022 · 7 comments
Closed
4 of 15 tasks
Labels
needs triage This issue has not been looked into

Comments

@Mateozmaldonado17
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When I use the AnyfilesInterceptor() interceptor I get this error:

(node:3446) UnhandledPromiseRejectionWarning: Error: Unexpected end of form at Multipart._final (/Users/mateozapatamaldonado/Documents/Apps/Personal/Authentication-Container/Authentication-Backend/node_modules/busboy/lib/types/multipart.js:588:17) at callFinal (internal/streams/writable.js:610:10) at processTicksAndRejections (internal/process/task_queues.js:82:21) (Use node --trace-warnings ...to show where the warning was created) (node:3446) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag--unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:3446) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Minimum reproduction code

https://codesandbox.io/s/brave-brattain-n670t2?file=/src/app.controller.ts

Steps to reproduce

No response

Expected behavior

I have searched for many sides but the error seems to be an internal error of the library, I would like it not to happen.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

9.0.0

Packages versions

`
{
"name": "authentication-backend",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write "src//*.ts" "test//.ts"",
"start": "nest start",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
"lint": "eslint "{src,apps,libs,test}/**/
.ts" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"test:e2e:watch": "jest --config ./test/jest-e2e.json --watch"
},
"dependencies": {
"@nestjs/axios": "^0.1.0",
"@nestjs/common": "^9.0.8",
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.0.8",
"@nestjs/mongoose": "^9.2.0",
"@nestjs/platform-express": "^9.0.8",
"@nestjs/typeorm": "^9.0.0-next.2",
"amazon-cognito-identity-js": "^5.2.10",
"aws-cognito-jwt-verifier": "^1.3.7",
"aws-sdk": "^2.1189.0",
"b64-to-blob": "^1.2.19",
"base64-blob": "^1.4.1",
"class-transformer": "^0.5.1",
"class-transformer-validator": "^0.9.1",
"class-validator": "^0.13.2",
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.5.1",
"mysql": "^2.18.1",
"nest-aws-sdk": "^3.0.0",
"nestjs-config-aws-ksm": "^1.0.5",
"nestjs-form-data": "^1.7.1",
"nestjs-i18n": "^9.1.5",
"node-fetch": "2.6.1",
"path": "^0.12.7",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
"rxjs": "^7.5.6",
"typeorm": "^0.3.7",
"typeorm-naming-strategies": "^4.1.0"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.1",
"@nestjs/testing": "^9.0.8",
"@types/jest": "^28.1.6",
"@types/multer": "^1.4.7",
"@types/node": "^18.6.4",
"@types/supertest": "^2.0.12",
"@types/uuid": "^8.3.4",
"@typescript-eslint/eslint-plugin": "^5.32.0",
"@typescript-eslint/parser": "^5.32.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"jest": "28.1.3",
"prettier": "^2.7.1",
"sqlite3": "^5.0.11",
"supertest": "^6.2.4",
"ts-jest": "^28.0.7",
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.1.0",
"typescript": "^4.7.4"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".\.spec\.ts$",
"transform": {
"^.+\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/
.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}

`

Node.js version

14

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@Mateozmaldonado17 Mateozmaldonado17 added the needs triage This issue has not been looked into label Sep 10, 2022
@jmcdo29
Copy link
Member

jmcdo29 commented Sep 10, 2022

I can't replicate this with the code you've provided. I exported to zip, unzipped, installed, used start:dev, and curl http://localhost:3000/ -F 'file=@package.json' -F 'file2=@package.json' -F 'fooFile=@README.md' just to try sending a couple of files at once. No errors or anything. Please provide the steps you're taking to reproduce this error with the reproduction provided

@Mateozmaldonado17
Copy link
Author

Sorry i can't share my Private repo, i'm researching about this problem, and i found that is caused for a bad format of a request in boundaries, i'm trying this in postman and this is his HTTP Request

`POST /inquiry HTTP/1.1
Host: localhost:3000
language: en
Authorization: Bearer eyJraWQiOiJzTWVtQjY4dEVlSnIzWkkwXC9kXC9xS1BYdElVVWhBMzBnSGRyTUVyc21zd1k9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiI4Yjc3Yjk5Ni1mMTczLTRkMTctOTI2Zi1lM2MyNTE5NTgyNjEiLCJkZXZpY2Vfa2V5IjoidXMtZWFzdC0xXzk3Mjc4Y2ZkLTZlYmItNDNlMy1iY2Q5LTczMzU0MzM4MWZkNCIsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTEuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0xX20zRTNHaDdrWiIsImNsaWVudF9pZCI6IjhlZXR2dDRjMzRnaGs5Mm9tcjNzcXN1cjAiLCJvcmlnaW5fanRpIjoiOWIwM2MyYTktMDIwMy00ODFjLWJmODgtNTcwNDBjOWU5Y2ZkIiwiZXZlbnRfaWQiOiI1ODFiNmZmOC1iNzhkLTQwOWYtOTMzMS1kZjQwMGU1YWY5YWUiLCJ0b2tlbl91c2UiOiJhY2Nlc3MiLCJzY29wZSI6ImF3cy5jb2duaXRvLnNpZ25pbi51c2VyLmFkbWluIiwiYXV0aF90aW1lIjoxNjYyODQ0MDQ2LCJleHAiOjE2NjI4NDc2NDYsImlhdCI6MTY2Mjg0NDA0NiwianRpIjoiZjJkODljY2ItMTFhNy00ZDBlLTg2YWEtMDdmMjY1NDg5Mjg1IiwidXNlcm5hbWUiOiJtYXRlbyJ9.U02ZLtd-GcZ0LggpwJ7d4PtVfWOGwmfAiNJj6DxUjUcv716ALlAjyk2A_K9mNcJVJdP2wkikSx4MefKQmOqyb5G99XJ2i9zeB6PE40-_a-gJm256chVOrdXImSfHCUL-0lijopKs9D0bJ825SsOpk_MqpJGbE68ZGiZousg-vAdfxmIolA2CZsTF8_MmtDLMyAioG5v-YhShZIAj6DHIlaez4c7ETHl2GoktK67Ow8yvQ-duw_NuH5prt18Gx2gKPOeb-8xqDrV86bytsVdCp8oWG_l-64GvXV4aEdmwX28GoK-8qcbXbNJ065muHq5XVh5ZHUx-8mYDhogGN7KjfA
Content-Length: 1424
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="id"

6b652e73-7f79-4fef-bfbf-b9808c08be3f
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="specialties"

["87ae9485-c2d1-4dc2-bbdc-80599c77f88c"]
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="countries"

["c842fd3d-b0e5-4473-b6f5-b546957876b9"]
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="procedures"

["329f84ff-7f27-49cb-a0e1-3ed5a93fa353"]
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="cities"

{"c842fd3d-b0e5-4473-b6f5-b546957876b9":["9ffc6437-871c-4ec6-85ae-5698a295d40f"]}
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="procedureFiles"

{"329f84ff-7f27-49cb-a0e1-3ed5a93fa353":["86aa6d24-558c-49d5-9659-d0cde3293f98.JPEG"]}
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="specialist"

{"87ae9485-c2d1-4dc2-bbdc-80599c77f88c":["07740df4-9d46-48a2-9d04-9fb229998e9d"]}
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="86aa6d24-558c-49d5-9659-d0cde3293f98.jpeg"
Content-Type: image/jpeg

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="files"; filename="WhatsApp Image 2022-09-05 at 12.06.14 PM.jpeg"
Content-Type:

(data)
----WebKitFormBoundary7MA4YWxkTrZu0gW
`

@Mateozmaldonado17
Copy link
Author

apparently this is happening since the form is not closing

@jmcdo29
Copy link
Member

jmcdo29 commented Sep 10, 2022

That sounds like it would bean error with multer (or even busboy) and not directly related to Nest (unless multer has already patched this and we haven't updated the multer package). I'd suggest replicating this, without Nest, and reporting it to the appropriate package's repository

@jmcdo29 jmcdo29 closed this as completed Sep 10, 2022
@max-mathieu
Copy link
Contributor

max-mathieu commented Jan 13, 2023

@jmcdo29 FYI we're been facing a similar issue, and here's where I'm at.

Some malformed requests can trigger those unhandled rejections (like it's filed here). It cannot be fixed by nest directly, and I'm still trying to figure out what's broken. This is concerning because any endpoint that leverages multer is a vector to take the full nestjs app down

That said, others cases of malformed requests are not triggering those out-of-band rejections, but are returned by Nest as 500 errors where they should be 400. There are 2 levels to it:

  • nest's MulterModule transformException doesn't map all the errors from multer
  • multer doesn't wrap all the errors from busboy (end of form, end of file, malformed headers) and bubbles them up as is. We could wait for multer to map these to errors, or, since we're mapping on error messages, this can be done directly here.

Anyways, I've opened #10880 for the mild cases, and I'm still looking at the issue between multer and busboy

@max-mathieu
Copy link
Contributor

FYI I tracked the first case where a malformed request can take down the nodejs/nestjs app, and opened an issue + PR with multer: expressjs/multer#1176

@eamon0989
Copy link

Any update on this? We are also facing the same issue where a malformed request crashes the service with the following error:

/Users/<user>/work/platform/node_modules/busboy/lib/types/multipart.js:555
      if (!this._complete) return cb(new Error('Unexpected end of form'));
                                     ^
Error: Unexpected end of form

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

4 participants