Been using the Azure Nodejs SDK which leverage's the REST API.
My Structure is as followes.
I have a piece of middle ware which attaches the azure service management object to every request:
var azure = require('azure'),
account = getAccount();
app.use(function(req, res, next){
try{
req.serviceManagement = azure.createServiceManagementService(account.subscriptionId, {
keyvalue: account.pem,
certvalue: account.pem
},{
apiversion: '2013-06-01',
serializetype: 'XML'
});
}catch(e){
return res.status(403).send(e);
}
next();
});
This allows me to easily access it in my routes.
Now the actual problem. When ever there appears to be a large amount of load on the API i get 403 errors on random requests, regardless of what the request actually is:
{ [Error: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.]
code: 'ForbiddenError',
message: 'The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.' }
I came to this conclusion because originally i was performing this method in a route. Its also worth noting that in the getHostedService
method i had to append ?embed-detail=true
to the url to get all the available details about the hosted service.
req.serviceManagement.listHostedServices(function(e, services){
async.map(services, function(service, mcb){
req.serviceManagement.getHostedService(service.ServiceName, function(e, serviceDetail){
//Do processing
mcb(e, serviceDetail);
});
}, function(error, servicesDetailed){
res.status(errpr ? 500 : 200).send(error || servicesDetailed);
});
});
async.map
will loop over the array given to it in parallel and call the first function passed to it over each element of the array, once each element is complete it will call the second function. Now if i used the series version, so it is only hitting azure one at a time, every single request worked perfectly. Not one random 403.
So I thought the problem was solved. Except its back this time when a colleague was performing windows updates to about 4-5 virtual machines at once. Im presuming this puts heavy load on azure in relation to our subscription and again causes random 403 errors on REST API calls. Once the updates were complete All my calls to the REST API work again and i don't get a single 403.
I'm at a complete loss as to what to do next. Is this an error on my end or azure? Is my workflow wrong? In my middle ware I've tried creating the azure service management object once up with my requires then appending that to each request but again with no success. I can control my workflow so that I'm not bombarding azure but if other activity like what's actually going on on the virtual machines can cause this than I'm a little shafted as that is completely out of my control.
Thanks in advance for any and all help. Stephen.