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

Calling close() removes all event listeners (including "error") #638

Closed
bminer opened this issue Dec 1, 2015 · 5 comments · Fixed by #764
Closed

Calling close() removes all event listeners (including "error") #638

bminer opened this issue Dec 1, 2015 · 5 comments · Fixed by #764

Comments

@bminer
Copy link

bminer commented Dec 1, 2015

When a SerialPort is closed by calling close(), all event listeners are removed (as per the documentation). This behavior might be undesired.

If one calls write on a closed serial port connection without passing a callback to the write method, an "error" event is emitted by default. So, calling port.write(buf); on a closed serial port can cause an "error" event to be emitted without an "error" event handler (even if the user created an "error" event handler before the SerialPort was closed). In this case, the default Node behavior for this is to throw an exception, which could crash the program.

@rwaldron
Copy link
Contributor

Just hit this as well. Even if I have registered an error event handler, there are no events registered when this: https://github.com/voodootikigod/node-serialport/blob/master/serialport.js#L293 is reached—which means that code is pointless.

@reconbot
Copy link
Member

This bananas

@rwaldron
Copy link
Contributor

(╯‵Д′)╯彡┻━┻

@reconbot
Copy link
Member

Tracking in #702

@reconbot
Copy link
Member

fixed in 3.0.0

@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.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants