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

Can't open more than three ports on win10 #914

Closed
konyee opened this issue Aug 23, 2016 · 16 comments
Closed

Can't open more than three ports on win10 #914

konyee opened this issue Aug 23, 2016 · 16 comments
Labels
bug feature-request Feature or Enhancement windows

Comments

@konyee
Copy link

konyee commented Aug 23, 2016

SerialPort version: 4.0.1
NodeJS Version: 4.4.7 and 6.3.1
Operating System and Hardware: Win10 64bit
Are you using Electron/Atom/NwJS?: no

(Run node -v && npm -v && python --version to get version numbers)
v4.4.7
2.15.8
Python 2.7.10

Summary of Problem

Cannot create more then 3 serialports on Win10.

Expected Behavior

Be open more ports.

Actual Behavior

If I create 4 or more it cannot be closed.
It also crashed my express webserver.

Steps and Code to Reproduce the Issue

If you put more than 3 portname to ports, the test will stuck after 'closing'.
If less then 4, everything is ok.

As I see the problem maybe at UV_THREADPOOL_SIZE
http://docs.libuv.org/en/v1.x/threadpool.html#

serialTest.txt

@konyee
Copy link
Author

konyee commented Aug 25, 2016

I found a workaround for this.
http://stackoverflow.com/questions/30983672/node-serialport-on-windows-with-multiple-devices-hangs

Set UV_THREADPOOL_SIZE enviroment variable larger than count of serial ports BEFORE you start your app. (Default value is 4)

@reconbot
Copy link
Member

reconbot commented Sep 2, 2016

I'm glad you found this. Sorry it's an issue. I'm going to keep this open pending the 5x release which might be able to address this issue on windows.

@reconbot reconbot added windows feature-request Feature or Enhancement labels Sep 2, 2016
@konyee
Copy link
Author

konyee commented Sep 9, 2016

You're welcome. :)

2016-09-02 5:12 GMT+02:00 Francis Gulotta notifications@github.com:

I'm glad you found this. Sorry it's an issue. I'm going to keep this open
pending the 5x release which might be able to address this issue on windows.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#914 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGnNYwnGID2_3u8dv31aUej_qUZ6nhOKks5ql5QagaJpZM4JrVQ-
.

@deandob
Copy link

deandob commented Sep 22, 2016

Would be great if 5.0 release could include a fix for this rather than setting environmental variables outside the program.

@reconbot
Copy link
Member

The current bindings require a thread per port, there's not much we can do about that other than rearchitect the bindings.

@deandob
Copy link

deandob commented Sep 23, 2016

Ok thanks for confirming. I'll factor the environment variable into the setup for my app.

@reconbot reconbot changed the title Bug when more than three ports on win10 Can't open more than three ports on win10 Oct 5, 2016
@Zensey
Copy link
Contributor

Zensey commented Nov 2, 2016

To work with many ports on windows one should use IO completion ports (IOCP) API.

  1. Create completion port: CreateIoCompletionPort
  2. Open port with overlapped flag, set port params. Add port fd to IOCP.
  3. Issue ReadFile for port fd.
  4. In separate thread do GetQueuedCompletionStatus in loop and get i/o state, grab data, emit events.

@reconbot reconbot added the bug label Nov 2, 2016
@reconbot
Copy link
Member

reconbot commented Nov 2, 2016

I completely agree, our current method of windows reading is far from optimal and this is the right way to go. I haven't explored it but it but I think uvpoll_t basically does that, and I'm hoping that we can use it. I haven't gotten anything to work yet, and I welcome any patches.

@Zensey
Copy link
Contributor

Zensey commented Nov 3, 2016

AFAIK libuv didn't have IOCP support, at least 1 year ago.

@jaredrolson
Copy link

Hi, I'm having this same problem and would really like to have 4+ ports open simultaneously.

I understand that I need to change an environment variable before the app is setup, but I don't understand how to do that. I think I'm supposed to paste this line of code somewhere:

process.env.UV_THREADPOOL_SIZE = 6;

But I don't understand where to put that code. Can someone point me in the right direction? I pasted at the very top of my main app, but it's not working.

Thanks

@reconbot
Copy link
Member

reconbot commented Mar 31, 2017 via email

@jaredrolson
Copy link

Perfect thanks. I have it working now. I'm running my code from the command prompt, and it worked when I entered this into the prompt before running my app:

set UV_THREADPOOL_SIZE=8

@jupe
Copy link

jupe commented Apr 1, 2017

I've same problem. Please mention this limitaion and env variable in release notes so people know about this.. Unfortunately it takes long time before I saw this issue and possible workaround fix ..

@reconbot
Copy link
Member

reconbot commented Apr 1, 2017 via email

@reconbot
Copy link
Member

reconbot commented Apr 1, 2017 via email

@reconbot
Copy link
Member

reconbot commented Jul 6, 2017

I've figured out the cause of this. I've opened #1221 as a feature request to fix this. If I can I'l have it out in the 5.0.0 release.

@reconbot reconbot closed this as completed Jul 6, 2017
@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
bug feature-request Feature or Enhancement windows
Development

No branches or pull requests

6 participants