node-serialport: Segfaults during `list()` that crashes Node when encountering certain types of serial ports
Summary of Problem
(Please answer all 3)
- What are you trying to do? Query the serial ports.
- What happens? I get a segmentation fault when I plug in a particular device.
- What should have happened? I should have seen the new device added.
Code to Reproduce the Issue
const serialport = require("serialport");
serialport.list().then(currentPorts => {
console.log(currentPorts);
});
Versions, Operating System and Hardware
- SerialPort@? 9.0.2
- Node.js v? 12.18.0
- Windows? Linux? Mac? Windows 10
- Hardware and chipset? Dialog DA16200 debug port
The DA16200 appears to create a SerialPort device that windows cannot assign to a COM port. Unfortunately, the node-serialport
module segfaults with no indication of an error when it encounters this device: I can’t even catch()
it and recover, the process just ends. Even when I run with DEBUG=*
I see no other messages. Windows Command Prompt prints nothing but Cygwin offers a clue:
Peter@CAPYBARA /cygdrive/c/Users/Peter/serialtmp
$ DEBUG=* node test-serial.js
serialport/bindings loading WindowsBinding +0ms
serialport/stream .list +0ms
Segmentation fault
Here is a picture of the orphan Serial Port appearing in Device Manager:
How do I enable better error handling so that my application doesn’t segfault due to serialport?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 21 (8 by maintainers)
@petertorelli @GazHank @hisasan see https://github.com/serialport/node-serialport/pull/2325
Thank you @hisasan for https://github.com/serialport/node-serialport/issues/2155#issuecomment-773729478 and @petertorelli for https://github.com/serialport/node-serialport/issues/2155#issuecomment-778842589 – you guys hit the nail on the head!
Let’s leave it open. We can let stale bot close it if nobody else pipes up.
I can confirm that the same issue is happening for our users (at least 5) who have devices listed under “Ports (COM & LPT)” without a COM port number. In one specific instance, the device without COM port number is a Brother HL-L2350DW printer.
Serialport 9.0.2 Node 12.13.0 Windows 10
Ours is an Electron app, so when the segfault occurs the entire window just goes blank, without any error messages. It took us forever to figure out what was going on, so thank you so much for reporting this @petertorelli !
Any workarounds for this one, @reconbot ?