Skip to content

Buggy close() routine - Node "hangs" #150

@bminer

Description

@bminer

The serial port does not properly close on Debian Linux. The "close" event is fired, however. In addition, Node will hang even after close() is called.

Code to reproduce:

var SerialPort = require("SerialPort").SerialPort;
var port = new SerialPort("/dev/ttySerial0", {
    "baudRate": 57600
});
port.on("open", function() {
    console.log("open", arguments);
    setTimeout(function() {
        console.log("Closing serial port");
        port.close();
    }, 2000);
});
port.on("error", function() {
    console.log("error", arguments);
});
port.on("data", function() {
    console.log("data", arguments);
});
port.on("close", function() {
    console.log("close", arguments);
});

Output when you run this program:

open {}
Closing serial port
close {}

Then... Node just hangs forever... (undesirably)

Furthermore, if I remove the serial port (i.e. /dev/ttySerial0 goes away), I get the following error:

events.js: 71
    throw arguments[1]; // Unhandled 'error' event
Error EIO, read

Then Node crashes. How could there be an unhandled error event if I am binding an event listener to the "error" event, as shown in the code above?

This is a bit buggy. Maybe the close() routine doesn't really release the serial port... I've found that if I try to re-use the port, an error occurs. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions