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

Network blocks with more than four simultaneous clients connections #63

Closed
jla opened this issue Dec 12, 2019 · 1 comment
Closed

Network blocks with more than four simultaneous clients connections #63

jla opened this issue Dec 12, 2019 · 1 comment

Comments

@jla
Copy link

jla commented Dec 12, 2019

When connecting to multiple devices if some of them goes down it blocks all the communication with the other devices:

var snap7 = require('node-snap7');

var LIMIT = 4

for (var i = 1; i < LIMIT + 1; i++) {
    console.log('Init Dummy: ' + i);
    var s7clientA = new snap7.S7Client();
    s7clientA.ConnectTo('192.168.0.10' + i, 0, 1, function(err) {   // Offline devices
        if(err) return console.log(' >> Connection failed. Code #' + err + ' - ' + s7clientA.ErrorText(err));
    });
}

console.log('Init Client');
var s7clientB = new snap7.S7Client();
s7clientB.ConnectTo('192.168.0.1', 0, 1, function(err) { // Online device
    if(err) return console.log(' >> Connection failed. Code #' + err + ' - ' + s7clientB.ErrorText(err));
    console.log('Client Connected');
});
Init Dummy: 1
Init Dummy: 2
Init Dummy: 3
Init Dummy: 4
Init Client

...after 30s...

 >> Connection failed. Code #60 -  TCP : Connection timed out
 >> Connection failed. Code #60 -  TCP : Connection timed out
 >> Connection failed. Code #60 -  TCP : Connection timed out
 >> Connection failed. Code #60 -  TCP : Connection timed out
Client Connected

With LIMIT = 3 it works as expected:

Init Dummy: 1
Init Dummy: 2
Init Dummy: 3
Init Client
Client Connected

...after 30s...

 >> Connection failed. Code #60 -  TCP : Connection timed out
 >> Connection failed. Code #60 -  TCP : Connection timed out
 >> Connection failed. Code #60 -  TCP : Connection timed out

I'm not sure if it's a problem in the Snap7 library. Any idea? Thanks!

@jla
Copy link
Author

jla commented Dec 12, 2019

Found it! There is a limit in the number of concurrent asynchronous operations in node, by default is four.
Each call to the snap7 library use one of the four available threads. This could be a problem with multiple devices and bad network connection.

Setting the UV_THREADPOOL_SIZE environment variable to a higher number (pe. the total number of devices) solve the problem.

@jla jla closed this as completed Dec 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant