Inifinit loop when device plugged, unplugged, write #302

Closed
badrstark opened this Issue Feb 5, 2014 · 9 comments

Projects

None yet

6 participants

@badrstark

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
Collaborator
reconbot commented Feb 5, 2014

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

@badrstark

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
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?

@JayBeavers JayBeavers added the linux label Feb 11, 2014
@badrstark

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

@badrstark badrstark closed this Feb 11, 2014
@badrstark badrstark reopened this Feb 11, 2014
@sturm
sturm 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

@vflyson
vflyson commented Jun 6, 2014

I'd like this fix here to be merged upstream, please: yateya@1328434

@reconbot
Collaborator
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 =)

@vflyson
vflyson 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

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(...)

@voodootikigod voodootikigod closed this in #345 Aug 7, 2014
@JeremyBYU JeremyBYU referenced this issue in morkai/h5.modbus May 26, 2015
Closed

Handling Loss of Connection (Serial) #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment