Uncaught exceptions can cause node to hang #282

bminer opened this Issue Dec 19, 2013 · 8 comments


None yet
5 participants

bminer commented Dec 19, 2013

In certain situations, process.exit(1) or an uncaught exception will cause the Node.js process to hang when using node-serialport. The desired behavior is for the Node process to die. Instead, the process remains open and just hangs.

I am working on some reproducible code to demonstrate this bug. I am fairly certain that node-serialport is the culprit... it reminds me of issue #150.

This problem occurs on node-serialport 1.2.5. Node 0.10.22. Debian Linux 7.0

bminer commented Dec 24, 2013

Update: I have narrowed the problem to an issue with the getaddrinfo system call (see related issue joyent/node#2868). When dns.lookup fails due to a network connectivity problem, there are long delays reading the serial port. Eventually, the getaddrinfo system call returns the ENOTFOUND error, and then Node hangs.

Why node-serialport causes this hang-up... I still don't know. But, it's probably related to getaddrinfo sharing the thread pool with node-serialport.

Very interesting and strange...

I also have this problem. I'm running on Rasbian kernel 3.10.24+, node v0.10.12. I like to resume stdin and then listen for the 'SIGINT' event on process. Then I cleanup open ports and other application stuff,and explicitly call process.exit(). If I call serialPort.close() in my SIGINT handler, then try to call process.exit(), it just hangs. I have to ctrl-Z and kill -9 node to recover.

This is really annoying, because I would like to call process.exit() in the serial.close() callback function to ensure everything is closed properly, but it just hangs.

So at this point, I just don't close the serial port. It seems to be fine; I'm just using the /dev/ttyAMA0 (rx/tx pins) on the rpi to talk to an arduino.

Anyone have any more info on this?


JayBeavers commented Jan 17, 2014

What a fascinating bug, great sleuthing @bminer! Do you have a recommended fix and if so could you submit a pull request?

bminer commented Jan 18, 2014

@JayBeavers - Unfortunately, I do not have a fix at this time. It's also pretty tough to reproduce the problem. (sigh)

If I find any more information, I will post back here.

bminer closed this Jan 18, 2014

bminer reopened this Jan 18, 2014


voodootikigod commented Dec 31, 2014

@bminer any update or data?

bminer commented Jan 6, 2015

Sadly, no. I do not have time ATM to debug this issue. However, I can say that libuv is working on separating the thread pools for different tasks (libuv/leps#4). And, they are working on an approach to allow reading from TTY/serial ports (libuv/libuv#19). So, eventually, these wonderful things will make it to Node.js.

In the meantime, I have been using node-serialport and other libs to address the issue, and I just deal with the bugs.


reconbot commented Mar 25, 2016

We've had a lot of similar bugs fixed as well as some major rewrites of our c++ code since this bug was filed. I sure hope we caught this bug, but since it was never quite identified, I'm closing this issue.

reconbot closed this Mar 25, 2016

bminer commented Mar 28, 2016

Sounds good, thanks. I'm not sure if it's still an issue or not either. I've been pretty happy with the stability improvements made to this lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment