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

Inifinit loop when device plugged, unplugged, write #302

Closed
badrstark opened this issue Feb 5, 2014 · 9 comments · Fixed by #345
Closed

Inifinit loop when device plugged, unplugged, write #302

badrstark opened this issue Feb 5, 2014 · 9 comments · Fixed by #345
Labels

Comments

@badrstark
Copy link

I am using serial-port with a USB device on ubunutu. I get infinite-loop using the following procedures:

  • plug the device.
  • Run nodejs which uses the device for while.
  • unplug the device
  • Try to write to the device
  • inifinit loop with this message "error: Error: Error Input/output error calling write(...)"
@reconbot
Copy link
Member

reconbot commented Feb 5, 2014

Can you share a stripped down version of your program that exhibits this behavior?

@badrstark
Copy link
Author

Stripped example, it sends a command periodically (every second). If an error occurs stop sending. Keep this script running for a while and then unplug the USB device, it calls the error callback infinite times.

var SerialPort = require("serialport").SerialPort
var sp = new SerialPort('/dev/ttyUSB0',
{baudrate: 115200,databits: 8,stopbits: 1,parity: "none",buffersize: 2048,flowcontrol: ["RTSCTS"],
    parser: require("serialport").parsers.readline("\n")
});

var sendFlag = true;
sp.on("error", function (e){
    console.log('error occured: ' + e + " at time " + Date.now());
    console.log("do not write to serial any more ");
    sendFlag = false;
});

sp.on("open", function (){
    console.log("opened!");
    setInterval(_sendCmd, 1000);
});

sp.on('data', function(d){ console.log(d + "\n"); });

function _sendCmd(){
    if(sendFlag){
        sp.write("AT\r",
            sp.drain(
            function (err, results){
                if (err) throw err;
                }
            )
        );
    }else{
        console.log("Not sending!");
    }
}

Here is a screen shot of the output, and notice that the error callback is called 9 times at the same microsecond!

serial_screen

@JayBeavers
Copy link
Collaborator

So can I restate your issue as "I receive more than one error event when I disconnect a device that has buffered data while running on Ubuntu. I expected to receive a disconnected event followed by an error event that told me that my buffered data was lost."

Are you running x86/x64 Ubuntu?

@badrstark
Copy link
Author

Yes, your description is exactly what I meant.
I am using Ubuntu 64bit.

@badrstark badrstark reopened this Feb 11, 2014
@ghost
Copy link

ghost commented May 12, 2014

I'm confirming this one, too.
64bit dual-core i7, debian, node 0.10.26

overloads my CPU, node process shows ~102%+ in my top
we need to wrap this error, to avoid hanging smaller boards

@snshn
Copy link

snshn commented Jun 6, 2014

I'd like this fix here to be merged upstream, please: https://github.com/yateya/node-serialport/commit/13284343c7aa125dd3275f0a28600c4a6a20b697

@reconbot
Copy link
Member

reconbot commented Jun 7, 2014

@flatr0ze can you rebase off the latest master? if anything to get the tests for #335 to pass. I'm not qualified enough to vet the patch however @JayBeavers and others will take a look =)

@snshn
Copy link

snshn commented Jun 7, 2014

it's not my fix, it's yateya who made it... I forked and am using it now as my npm, since the infinite loop was overloading my CPU

@tonini46
Copy link

Hey, I am getting a similar error too using the Duino module and I am using a Live-USB running ubunutu to toggle an led, on and off. The terminal error result is: (please help)
root@ubuntu:/home/ubuntu# nodejs led.js
1402773380169 duino info attempting to find Arduino board
1402773380177 duino info set pin 13 mode to out
1402773380178 duino info serial not ready, buffering message: 0013001
1402773380186 duino info found board at undefined
1402773380186 duino info binding serial events
1402773380688 duino info board ready
1402773380688 duino info sending debug mode toggle on to board
1402773380689 duino write 9900001
1402773380689 duino info processing buffered messages
1402773380689 duino info writing buffered message
1402773380689 duino write 0013001

events.js:72
throw er; // Unhandled 'error' event
^
Error: Error Input/output error calling write(...)

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

Successfully merging a pull request may close this issue.

5 participants