Timeout Control for Next.js Server Responses #69452
andorthehood
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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