You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To allow developers to configure a global timeout for server actions and route handlers.
To prevent indefinite waiting periods that can lead to performance issues or downtime.
To be able to improve user experience by notifying users that something was taking unusually long, and it would be better to retry at this point.
Non-Goals
The feature is about server-side timeouts and does not handle client-side timeouts or retries.
It is a global timeout setting and does not offer per-request customization.
Background
Currently, in Next.js, it is possible to delay a server response indefinitely. This can be demonstrated by adding long setTimeout calls in server functions, which causes the server to wait without returning a response. This issue can also happen because of bugs in the application, unoptimized long-running operations, when relying on slow API calls, or when the application is under a high load.
Other Node.js frameworks and libraries usually provide access to the HTTP server instance, or giving developers more control over request handling and timeouts through configuration. Unfortunately, Next.js does neither of these, and the only alternative solution would be to write a custom middleware to manage timeouts by starting setTimeout calls. I think this approach is cumbersome and less efficient compared to using native options that Node.js provides.
Proposal
I propose two solutions:
Expose the server instance: Modify the createServer function to return the HTTP server instance. This would allow developers who use a custom server to customize it to their needs, including setting timeouts and other configurations directly on the server instance.
Add a --timeout option in the next start CLI, along with support for a TIMEOUT environment variable for developers who are using the standalone output. (Similar to the existing --keepAliveTimeout option and KEEP_ALIVE_TIMEOUT environment variable.)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Goals
Non-Goals
Background
Currently, in Next.js, it is possible to delay a server response indefinitely. This can be demonstrated by adding long setTimeout calls in server functions, which causes the server to wait without returning a response. This issue can also happen because of bugs in the application, unoptimized long-running operations, when relying on slow API calls, or when the application is under a high load.
Other Node.js frameworks and libraries usually provide access to the HTTP server instance, or giving developers more control over request handling and timeouts through configuration. Unfortunately, Next.js does neither of these, and the only alternative solution would be to write a custom middleware to manage timeouts by starting setTimeout calls. I think this approach is cumbersome and less efficient compared to using native options that Node.js provides.
Proposal
I propose two solutions:
Expose the server instance: Modify the
createServer
function to return the HTTP server instance. This would allow developers who use a custom server to customize it to their needs, including setting timeouts and other configurations directly on the server instance.Add a
--timeout
option in thenext start
CLI, along with support for aTIMEOUT
environment variable for developers who are using the standalone output. (Similar to the existing--keepAliveTimeout
option andKEEP_ALIVE_TIMEOUT
environment variable.)Once this feature proposal is accepted, I plan to open a pull request to implement one or both of these solutions. Preview: canary...andormade:next.js:add-timeout-option
Beta Was this translation helpful? Give feedback.
All reactions