Ensure process exits after build completes (#23207)

This ensures we exit the build process after the build completes even if timers/connections are left open since this can cause the process to hang indefinitely. This was the previous behavior although got changed un-intentionally in e27b7e996d

This updates our production test with an open timer to ensure it doesn't block the process from completing.
This commit is contained in:
JJ Kasper 2021-03-19 03:06:28 -05:00 committed by GitHub
parent e2cdf6d581
commit b6bb110aca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -106,7 +106,15 @@ if (typeof React.Suspense === 'undefined') {
process.on('SIGTERM', () => process.exit(0))
process.on('SIGINT', () => process.exit(0))
commands[command]().then((exec) => exec(forwardedArgs))
commands[command]()
.then((exec) => exec(forwardedArgs))
.then(() => {
if (command === 'build') {
// ensure process exits after build completes so open handles/connections
// don't cause process to hang
process.exit(0)
}
})
if (command === 'dev') {
const { CONFIG_FILE } = require('../next-server/lib/constants')

View file

@ -1,3 +1,6 @@
// intervals/open connections shouldn't block build from exiting
setInterval(() => {}, 250)
module.exports = {
onDemandEntries: {
// Make sure entries are not getting disposed.