Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unreference underlying socket to prevent process hangs

See original GitHub issue

We 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:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

jsocolcommented, Feb 7, 2018

It is pretty easy to work around, for sure. This is what we’ve done, since we’re wrapping the StatsD class:

class Metrics extends StatsD {
  constructor(options) {

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.

bdeittecommented, Jun 6, 2020

Fixed in 7.5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

process hangs on socket recvmsg call while receiving ...
I have a server process (C program)which does mmap for a physical memory of size around 70MB and when I'm sending this entire...
Read more >
hot-shots - UNPKG
26, * @ralphiech Add missing error handler when socket is not created ... 41, * @benblack86 Unreference underlying socket/interval to prevent process hangs....
Read more >
multiprocessing — Process-based parallelism — Python 3.11 ...
A library which wants to use a particular start method should probably use get_context() to avoid interfering with the choice of the library...
Read more >
Document - s700_800 11.11 Cumulative STREAMS ... - HPE Support
System hangs where one of the processors is busy processing in the stream head ... The address that was left behind for a...
Read more >
4.119. kernel Red Hat Enterprise Linux 6 | Red Hat Customer Portal
The system no longer hangs and kernel no longer panics in this scenario. ... skb_hints is now properly cleared from the socket, thus...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found