hendrikw01 / tr-064

TR-064 - UPnP/IGD for node.js
Apache License 2.0
35 stars 24 forks source link

503 error (Auth. failed), when querying multiple Services #10

Open derandiunddasbo opened 8 years ago

derandiunddasbo commented 8 years ago

Here is a (not so) small example using the tr064 lib, torturing a FritzBox 7490 device with obviously to many simultaneous SOAP requests, when trying to retrieve info of all three wifi services (2.4 GHz, 5 GHz and Guest WiFi):

var tr = require("tr-064");
var tr064 = new tr.TR064();
tr064.initTR064Device("fritz.box", 49000, function (err, device) {
    if (!err) {
        device.startEncryptedCommunication(function (err, sslDev) {
            if (!err) {
                sslDev.login([user],[pass]);

                var service_WLANConfiguration = sslDev.services["urn:dslforum-org:service:WLANConfiguration:1"];
                service_WLANConfiguration.actions.GetInfo(function(err, result){console.log("WLANConfiguration:1#GetInfo",result);});
                service_WLANConfiguration.actions.GetStatistics(function(err, result){console.log("WLANConfiguration:1#GetStatistics",result);});

                var service_WLANConfiguration = sslDev.services["urn:dslforum-org:service:WLANConfiguration:2"];
                service_WLANConfiguration.actions.GetInfo(function(err, result){console.log("WLANConfiguration:2#GetInfo",result);});
                service_WLANConfiguration.actions.GetStatistics(function(err, result){console.log("WLANConfiguration:2#GetStatistics",result);});

                var service_WLANConfiguration = sslDev.services["urn:dslforum-org:service:WLANConfiguration:3"];
                service_WLANConfiguration.actions.GetInfo(function(err, result){console.log("WLANConfiguration:3#GetInfo",result);});
                service_WLANConfiguration.actions.GetStatistics(function(err, result){console.log("WLANConfiguration:3#GetStatistics",result);});
            }
        });
    }
});

And this is the result:

WLANConfiguration:1#GetStatistics { faultcode: 's:Client',
  faultstring: 'UPnPError',
  detail:
   { UPnPError:
      { '$': [Object],
        errorCode: '503',
        errorDescription: 'Auth. failed' } } }
WLANConfiguration:3#GetInfo { faultcode: 's:Client',
  faultstring: 'UPnPError',
  detail:
   { UPnPError:
      { '$': [Object],
        errorCode: '503',
        errorDescription: 'Auth. failed' } } }
WLANConfiguration:3#GetStatistics { faultcode: 's:Client',
  faultstring: 'UPnPError',
  detail:
   { UPnPError:
      { '$': [Object],
        errorCode: '503',
        errorDescription: 'Auth. failed' } } }
WLANConfiguration:1#GetInfo { NewEnable: '1',
  NewStatus: 'Up',
[...]
  NewAllowedCharsPSK: '0123456789ABCDEFabcdef' }
WLANConfiguration:2#GetStatistics { NewTotalPacketsSent: '0', NewTotalPacketsReceived: '0' }
WLANConfiguration:2#GetInfo { NewEnable: '1',
  NewStatus: 'Up',
[...]
  NewAllowedCharsPSK: '0123456789ABCDEFabcdef' }

In this case three requests got through (WLANConfiguration:1#GetInfo, WLANConfiguration:2#GetInfo and WLANConfiguration:2#GetStatistics) while the other three failed with an 'Auth. failed' error.

When running this multiple times, three or more of the six requests randomly fail while the others deliver their results.

I had similar issues in other programming languages and it became apparent, that the FritzBox isn't able to handle more than three (SSL ?) connections to it's TR-064 interface simultaneously.

But is there a good way to handle this issue? Does anyone use this library to fire multiple SOAP requests to a FritzBox device in a nodejs script? And if so: How do you prevent the script from sending too many requests simultaneously and risking connection errors?

iMarvinS commented 8 years ago

I have exactly the same problem. I cannot call more than 3 actions no mater which service I use. The 4. action call always gives the same unauthenticated error as seen above me. Currently I´m instantiating a new device instance each time I call a action but this seems to end up in memory issues which does not seem to be the right way. Hope someone can fix this issue. I´ve already looked into the code but I cannot really understand where the issue is.