Skip to content
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

[linux] open file descriptor leak on serialport.open(), fd is not closed properly on serialport.close() #544

Closed
finim opened this issue Jun 16, 2015 · 5 comments

Comments

@finim
Copy link

finim commented Jun 16, 2015

On linux, when you open() and close() the serial port connection, the file descriptor to the device (e.g. to /dev/ttyUSB0) will not be closed properly.
I've written a simple application that will open and close the connection to the serial port every second.
When you watch the file descriptors with 'lsof -c node' you will see that on every call to open() a new file descriptor is opened that will not be closed on close();

Used node version: 0.10.x
Used serialport module: 1.7.4

Example application to test the issue (it will open an close the serialport every second):

var serialport = require('serialport');
var portConnection = new serialport.SerialPort('/dev/ttyUSB0',
    {
        baudrate: 9600
    },
    false
);

var openClosePortEverySecond = function () {
    portConnection.open(function (error) {
        if (typeof error !== 'undefined') {
            console.log('failed to open serialport');
            console.log(error);
        } else {
            console.log('serialport opened');
            portConnection.close(function (error) {
                if (typeof error !== 'undefined') {
                    console.log('failed to close serialport');
                    console.log(error);
                } else {
                    console.log('serialport closed');
                    setTimeout(function() {
                        openClosePortEverySecond();
                    },1000);
                }
            });
        }
    });
};

openClosePortEverySecond() ;
process.stdin.resume();

You can watch the open file descriptors with: watch -n1 "lsof -c node | wc -l"

@finim
Copy link
Author

finim commented Jun 16, 2015

Update: it seems that this issue is only in the latest version(s), i've tested 3 versions:
1.7.4 : leaking
1.7.1 : not leaking
1.6.2 : not leaking

@gnomex
Copy link

gnomex commented Jun 17, 2015

I got the same issue... I'm using node v0.12.4 and serialport: 1.7.4. The kernel version is 3.16.0-40-generic.

I have tried your example code with false and next true values on portConnection, both had the issue.

@koprda
Copy link

koprda commented Sep 4, 2015

I got the issue ...
serialport: 1.7.4.

handle is open 2 times in serialport_unix.cpp

void EIO_Open(uv_work_t* req) {
...
int fd = open(data->path, flags);

if(-1 == setup(fd, data)){
...

int setup(int fd, OpenBaton *data) {
...
fd = open(data->path, flags)

@reconbot
Copy link
Member

reconbot commented Apr 6, 2016

We fixed a ton of bugs in our latest beta specifically ones addressing this issue. #733 Please try it out serialport@2.0.7-beta4 and report back!

@reconbot
Copy link
Member

reconbot commented Apr 7, 2016

I'm going to close this as we've confirmed this bug is fixed. Please reopen or make a new issue if you have more issues! Thanks for reporting it and tracking down the issue!

@reconbot reconbot closed this as completed Apr 7, 2016
@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants