New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Node Process does not exit until device is disconnected #173
Comments
Could you give a link to your code? |
@todbot After a bit more digging, this seems to be an interaction with the bleno library. Here is the smallest test case I could make to reproduce the issue: "use strict";
const HID = require("node-hid");
require("bleno");
function findDevice() {
const devices = HID.devices();
for (const device of devices) {
if (device.vendorId === 2049 && device.productId === 2) { // I'm looking for a card reader
console.log("HID found");
return new HID.HID(device.path);
}
}
}
const hid = findDevice();
hid.on("data", function (buffer) {
console.log(buffer);
}); |
I have experienced this too, in a different project. In my case it was more obvious when there was a different bug with writing to the device (going off of memory at the moment.) My suspicion is the read loop opened to support the |
Yes, it's the EventEmitter inside node-hid keeping the process. Isn't this expected behavior? To cancel the pending read, you should call |
@todbot Yes, the listener on the EventEmitter will keep the process running until it is removed. I understand that is expected behavior. What I am describing is that the Node process will not exit when sent a Please let me know if you were able to run the sample app and see what I am observing. Thanks. |
Hmm. Yes, I can kill the Node process by doing Ctrl-C in the terminal. I've not tried |
I just verified a simple I don't have a test for the currently published node-hid on npmjs, so that could conceivably be different, since there is a new version of the underlying hidapi C library in the github version. The command I use to test and kill is:
|
@todbot Can you run the same simple example but also install |
After a long search I came to notice I have the same issue.
Did anyone find a way to (force) disconnect the listener and/or HID? |
I had this issue also, and found that I could workaround it by calling There's an open issue from 2017 about this undocumented function: #216 |
Whatever To do async reading, As we get more updates to It's very possible there are bugs in the code that handles this and it will be very platform-dependent, since Mac, Windows, and Linux all do HID in different ways. If anyone can provide a small working bit of sample code that goes against a commonly available piece of hardware, please let me know. We will get the hardware and test it with |
This is still happening to me when calling
Is this related to electron/electron#20425? The description matches. Why wouldn't this impact regular Node? This code reproduces the issue in Electron but not in Node:
Removing the |
When running a Node app from the command line, I have noticed that the Node process will not exit until the HID is disconnected from the computer. I have observed this behavior on both a Mac (macOS 10.12.1, Node v4.6.0) and Raspberry Pi 3 (Node 4.5.0).
A couple examples:
If I use the
ctrl-C
shortcut on a running Node app, I will not be returned to the prompt until I disconnect the USB HID that the app was communicating with.Similarly, if the app crashes because of an un-caught error, it will not return to the prompt until I disconnect the USB HID.
I had not experienced this behavior before beginning to use the
node-hid
library. Any clarification on why the app is behaving this way is appreciated.The text was updated successfully, but these errors were encountered: