peter-murray / node-hue-api

Node.js Library for interacting with the Philips Hue Bridge and Lights
Apache License 2.0
1.19k stars 145 forks source link

ECONNRESET for many lightStatus calls #53

Closed PSeitz closed 8 years ago

PSeitz commented 9 years ago

Hi,

I have this case, where I get a connection reset when obtaining the lightStatus for many lamps (around 8). My current solution is to use a queue, but it would be nice to bind it to the open connections or unresolved promises.

Error: write ECONNRESET at exports._errnoException (util.js:746:11) at Socket._writeGeneric (net.js:681:26) at Socket. (net.js:637:12) at Socket.g (events.js:199:16) at Socket.emit (events.js:129:20) at TCPConnectWrap.afterConnect as oncomplete

peter-murray commented 9 years ago

Hi,

Can you please provide me with an example application or code that replicates this issue. I cannot manage to reproduce it on my bridge, and that was after querying 19 bulbs attached to the bridge.

Can you also provide me with the bridge firmware and software versions.

Thanks

PSeitz commented 9 years ago

I could reproduce it on my windows machine and on my rasperry pi. Both are connected via LAN. 7 Lights work fine, 8 and above produce an ECONNRESET

Bride Version: 01024156 node v0.12.1 / v0.12.0 hue api 1.0.5

var HueApi = require("node-hue-api").HueApi;

var hostname = "hostname";
var token = "token";

var api = new HueApi(hostname, token);

api.lights(function(err, result) {
    console.log("Get Light Status of all");
    for (var i = 0; i < result.lights.length; i++) {
        api.lightStatus(result.lights[i].id, function(err, result) {
            if (err) throw err;
        });
    }
});
peter-murray commented 9 years ago

Thanks, its a problem in Node.js 0.12.x, it does not occur under 0.10.x versions. I will look further into the cause and issue a fix for it.

peter-murray commented 8 years ago

This appears to have been solved in release 2.0.0-RC1 of the library (it is available from npmjs.org).

This release has swapped out the http request library with axios which upon simple testing appears to have eliminated this issue.