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

Middleware causes post requests larger than 64kb to hang #39593

Closed
1 task done
arvind-agarwal opened this issue Aug 14, 2022 · 4 comments
Closed
1 task done

Middleware causes post requests larger than 64kb to hang #39593

arvind-agarwal opened this issue Aug 14, 2022 · 4 comments
Labels
bug Issue was opened via the bug report template.

Comments

@arvind-agarwal
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Wed Aug 25 23:20:18 UTC 2021
Binaries:
Node: 18.3.0
npm: 8.11.0
Yarn: N/A
pnpm: N/A
Relevant packages:
next: 12.2.6-canary.0
eslint-config-next: 12.2.5
react: 18.2.0
react-dom: 18.2.0

What browser are you using? (if relevant)

Not relevant

How are you deploying your application? (if relevant)

Not relevant

Describe the Bug

I am facing an issue with large post body with middleware, If the post body size is larger than 64k it hangs the client for a long time and is not processed. I zeroed it down on issue with middleware. If I introduce the middleware (even that does not do anything), than the post request does not succeed.

Steps to reproduce.

  1. Create a brand new project using create-next-app
  2. Create a middleware.js file in root of the project
export function middleware(request) {
  console.log(request.url);
}
  1. Start the above server using
npm run dev
  1. Start another terminal session
  2. Install axios
npm install axios 
  1. Create a file in root testRequest.js, needs axios as dependency
const axios=require("axios");

axios.post("http://localhost:3000/test", {
  "x": '1'.repeat(1024*64)
}).then(function (response) {
  console.log(response);
})
.catch(function (error) {
  console.log(error);
});
  1. Run the file using node testRequest.js. This process will hang and will not finish.

If I reduce the request size by changing multiple in repeat to 63, the request will not hang and 404 error response will be returned.

Expected Behavior

Expected behavior is that on running the testRequest, I should immediately get 404 response and an error message should be consoled.

However if the request is larger than 64k, it hangs and does not print the error.

Link to reproduction

https://codesandbox.io/s/mutable-flower-z3qgzd?file=/testRequest.js

To Reproduce

  1. Codesandbox, will automatically run the base nextjs project.
  2. Open another terminal tab in Codesandbox.
  3. Execute node testRequest.js, it should print the url in nextjs terminal tab, however the execution of the node program will hang. Kill this program. This file generates request of 100kb in size hence it hangs.
  4. Execute node testRequestLessThan64.js, this should succeed and print a message in console.
@arvind-agarwal arvind-agarwal added the bug Issue was opened via the bug report template. label Aug 14, 2022
@Marcelx8
Copy link

A similar issue was raised here #39262 (comment) where a post request of 16kb and larger body resulted in a pending state. See if v12.2.2 works if you can downgrade temporarily. That version has fixed my issue.

@hmdnprks
Copy link

Downgrading to v12.2.2 resolve my issue with uploading a file larger than 64kb. In v12.2.3, I have to remove the middleware file.

@ijjk
Copy link
Member

ijjk commented Aug 16, 2022

Closing as a duplicate of #39262

@ijjk ijjk closed this as completed Aug 16, 2022
@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

4 participants