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

Request "self.req.abort is not a function" #65

Closed cascornelissen closed 8 years ago

cascornelissen commented 8 years ago

I'm running into an issue when using node-hue-api from within Electron. It seems that every function I run (e.g. api.config(), or api.registerUser()) returns the following error:

Uncaught TypeError: self.req.abort is not a function

The error is thrown from node_modules/request/request.js:1340 and I'm not running into this issue when going to the project in Chrome via Browsersync.

I'm running the latest version of node-hue-api (1.2.1), and I'm using Electron v0.35.4.

Any ideas on what's causing this and how to fix it?

cascornelissen commented 8 years ago

If I quickly run multiple requests (api.registerUser, +5 times) I'm running into the same issue as described in this StackOverflow question and the Uncaught TypeError: self.req.abort is not a function error shows up too. Any chance node-hue-api is not consuming the data as explained in the answer?

cascornelissen commented 8 years ago

I switched to nw.js and I'm running into the exact same problem...

CC @peter-murray

peter-murray commented 8 years ago

Why are you trying to register a user so many times?

I have not had a chance to look into the register user code, but it does look like that the connections are not being closed out. I will put together a set of tests for this to check if this is actually an issue on my side. Where is the error actually coming from, do you have a point in the code? It looks like it may be coming from within the request library, not mine.

As for upping the limit, you can set that directly yourself, and the http.globalAgent.maxSocket is a global.

cascornelissen commented 8 years ago

I'm executing registerUser at an interval since I was having trouble reaching my hub within 30 seconds. I'm not trying to register a user multiple times a second, I'm just retrying after a set amount of seconds (5 seconds currently)/

What you're saying is probably correct though, the amount of requests exceeds a certain number (which is somehow set it while using it through Electron/NW, because it seems to work correctly in a browser). I stated the point in the code in my original post: node_modules/request/request.js:1340.

I'll try and play with the max socket limit.

cascornelissen commented 8 years ago

@peter-murray, I've been trying and testing a lot and I came up with the following script (which gets combined with node-hue-api via browserify) that throws the Uncaught TypeError: self.req.abort is not a function error when run through Electron/NW.js but successfully logs the resulting configuration object when run in a browser.

var hue = require('node-hue-api'),
    api = new hue.HueApi('192.168.x.x', 'xxx');

api.config().then(function(result) {
    console.log(result);
}).done();
peter-murray commented 8 years ago

I have just created a 2.0.0-RC1 release of the library that now uses a different http request library, axios.

Can you try to use that and see if that clears up the problems you are experiencing? Also can you confirm if you are still converting this library using browserify?

Thanks

cascornelissen commented 8 years ago

@peter-murray, you are an absolute hero! I updated to 2.0.0-RC1 and that finally resolved the problems I was having.

Probably unrelated now but yes I am still using your library in combination with browserify.