"After" function blocking API route responses #77813
Replies: 3 comments 1 reply
-
Hey! This might be happening because Vercel’s serverless functions don’t keep running after the response is sent, so the after() function ends up blocking in production. You can try explicitly setting the runtime to 'nodejs' or use a background job/queue for heavier tasks. For quick fixes, you could also send non-blocking fetch() calls without await. |
Beta Was this translation helpful? Give feedback.
-
Vercel does support this though, https://vercel.com/docs/functions/functions-api-reference/vercel-functions-package, I wonder if you can contact Vercel support, or open an issue here, https://github.com/vercel/vercel/issues?q=is%3Aissue%20state%3Aopen%20 I think |
Beta Was this translation helpful? Give feedback.
-
Thanks for the replies, @icyJoseph and @5shine1. When we awoke this morning, we found that the issue had righted itself: our Presumably a transient issue with our deployment on Vercel. |
Beta Was this translation helpful? Give feedback.
-
Summary
Curious if anyone else is experiencing this issue. Our app uses the
after
function in a number of API routes, mostly for analytics calls but also for some heavier computations/functionality that we don't want blocking the response. We hadn't encountered any problems until this morning, when suddenly ourafter
functions began to block the response, i.e., requests wouldn't register as complete until all logic in theafter
functions had finished running.In local development, the
after
functions still work as expected. It's only in deployed versions that we're encountering this issue.To make sure the problem wasn't something else in the codebase, I created a new NextJS project with the single API route shown below. Sure enough, it works as expected in local development but takes the full 10 seconds to respond when deployed on Vercel.
Any help greatly appreciated.
You can test this API route for yourself at the URL below
Additional information
No response
Example
https://nextjs-test-ten-hazel-95.vercel.app/
Beta Was this translation helpful? Give feedback.
All reactions