Next.js Discord

Discord Forum

Route handler that takes too long is crashing dev and start.

Unanswered
Brokenwind posted this in #help-forum
Open in Discord
I have a route handler that may take 20 minutes to run (depending on user input). During the first 5 minutes, I am still able to access other pages and do whatever, even access other route handlers and there are no issues there. After that 5 minute mark, nothing is accessible and everything is loading until that route handler is completed. I really need help on how to solve this because nothing in docs suggest how to resolve this.

I'm using latest next 15.1.6, node 23.7.0. I tried to remove .next and node_modules and reinstall eveything. This seems to be a normal Next (or Node) behavior.

3 Replies

Asian black bear
I don't know why this is happening in particular, but an API endpoint that takes up to 20 minutes to respond is an awful design. Decouple your web server from the job being run using a proper job queue and you're likely going to solve this problem.
I did more research and it appears when others do it too, the main thread is being blocked by the API, worker threads are one of the solution brought up