Unreference underlying socket to prevent process hangs
See original GitHub issueWe recently started seeing our test suites hang across projects that were using hot-shots (we have our own wrapper which sets some defaults) and tracked it down to a new behavior in mocha 4, which prevents the test process from exiting while there are open handles.
In theory, this could also impact clean shutdowns of non-test processes as well where StatsD
objects may not be able to be informed of a shutdown signal (for instance, if a library creates its own stats client). I have not, however, personally observed that behavior, but it seems more likely in scripts or other context that are expected to shut themselves down, rather than serve forever, e.g. a cron task.
Calling socket.unref()
after creating the socket allows node to exit if the hot-shots socket is the last open handle. It may, however, introduce some risk of losing metrics before they’re sent.
I’m not sure if this is worth doing in the library—or perhaps adding a opt-in option for—but I wanted to write it down in case other people run into it.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:8 (2 by maintainers)
Top GitHub Comments
It is pretty easy to work around, for sure. This is what we’ve done, since we’re wrapping the
StatsD
class:but that could also be handled by any code after instantiating a
StatsD
instance. I’m not sure how “public”this.socket
is, but as long as it doesn’t change, user-land code can fix this.Fixed in 7.5.0