greim/hoxy

Hoxy is preventing Node from exiting

Opened this issue · 2 comments

If I so much as require('hoxy'), Node will never exit.

This is problematic for the end-user. They go to Control-C on my server and it never dies, as I trap SIGINT and expect proxy.close() to exit gracefully.

hoxy 3.2.0
node 7.0.0
npm 3.10.9

I used the why-is-node-running module to debug this and it pointed a finger at the server.listen() in cycle.js.

I'm not very familiar with this portion of the codebase, but the solutions that seem obvious to me are:

  • Only start listening when the user calls listen() on a Hoxy instance. Otherwise, it is surprising that the program remains open forever.
  • Stop listening / close() at a reasonable time so that graceful shutdown works as expected. Options might be:
    • Handle SIGINT and close.
    • Keep track of whether there are listening hoxy instances. Close when there are no more.
    • Use a class instead of a singleton. Listen / close in tandem with each hoxy instance.

+1 having this problem. Simple example:

const hoxy = require('hoxy')

const proxy = hoxy.createServer().listen('1234')

proxy.close(function(err) {
  if (err) throw err

  console.log('The proxy is no longer accepting new connections.')
})

The output is The proxy is no longer accepting new connections., but my process is still up.