Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server.close does not allow Node process to exit in dev mode #2540

Closed
1 task done
beverlycodes opened this issue Jul 12, 2017 · 3 comments · Fixed by #3540
Closed
1 task done

Server.close does not allow Node process to exit in dev mode #2540

beverlycodes opened this issue Jul 12, 2017 · 3 comments · Fixed by #3540

Comments

@beverlycodes
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Assuming I've assigned an instance of next to the variable app and called app.prepare(), calling app.close() should stop all middleware and allow the Node process to exit.

Current Behavior

In dev mode, the Node process keeps running with some middleware remaining active. If a page was recently accessed, the "Disposing active pages" message will eventually be logged after app.close() was called, indicating that something has not stopped. It will not stop after disposing pages either.

When not running in dev mode, the Node process will exit as expected.

Steps to Reproduce (for bugs)

  1. Follow the basic setup instructions, then create the following server.js:
const path = require('path');

const { createServer } = require('http')
const { parse } = require('url')
const next = require('next')

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev, dir: path.resolve(__dirname) })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  const http = createServer((req, res) => {
    const { parsedUrl } = parse(req.url, true)
    handle(req, res, parsedUrl)
      .then(() => http.close())
      .then(() => app.close())
  })

  http.listen(8080)
})
  1. Build with npm run build

  2. Run node server.js and point browser at app. The Node process will NOT exit after request is handled. Must Ctrl-C to exit.

  3. Run NODE_ENV=production node server.js and point browser at app. The Node process will exit after request is handled.

Context

Came across this while working on a monitoring app to start/discover/stop instances of a Next app. Instances wouldn't exit when told to via a /stop http request.

Your Environment

Tech Version
next 3.0.1-beta.13
node 7.10.0
OS Ubuntu 14.04.5 LTS
browser Chrome
@oliviertassinari
Copy link
Contributor

I believe it's the hot reloading module that's preventing the process to exit. I have noticed the same behavior when implementing a soft kill handler.

@lucleray
Copy link
Member

lucleray commented Jan 5, 2018

The hot-reloader starting in dev mode seems to start two different webpack middlewares :

  • webpackDevMiddleware
  • WebpackHotMiddleware

https://github.com/zeit/next.js/blob/57a0fc432ce2efc5486a8f27f6dd1b63bd5986c7/server/hot-reloader.js#L196-L200

But it only stops webpackDevMiddleware :
https://github.com/zeit/next.js/blob/57a0fc432ce2efc5486a8f27f6dd1b63bd5986c7/server/hot-reloader.js#L59-L69

The module webpack-hot-middleware does not have any close method yet.
But it is an open issue : webpack-contrib/webpack-hot-middleware#176

I guess the progress on this depends on the progress on the issue of webpack-hot-middleware.

@lucleray
Copy link
Member

lucleray commented Jan 6, 2018

I found out that the actual problem was coming from onDemandEntryHandler.

I suggest a solution to solve it with this pull request : #3540

@lock lock bot locked as resolved and limited conversation to collaborators Jan 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants