Closed 2MuchTech closed 8 years ago
I've done a little debugging, but I still don't know how to fix the problem. The issue only occurs when basic auth is enabled. For some reason the requestHandler
function in server.js is getting called three (3) times for each "say" command invoked by a browser. The first 2 timescredentials
gets assigned correctly, but on the third call credentials
is left undefined after the call to auth(req)
. The subsequent res.setHeader
function then generates the error message I noted in my original post and the program aborts.
I have noticed that on the third call to the requestHandler
function, req.headers
contains an entry connection = "close"
, so I'm going to try to modify the code to look for this and return from the function. Since I don't know what the heck is supposed to happen on this third call, I'm guessing my "solution" isn't going to be correct even if it sidesteps the crash bug. I'd appreciate some suggestions for the proper way to handle this. Thanks!
Upon further review, it appears the variable err
is undefined in the third call to the requestHandler
function, so I ended up just moving some of your existing code around and it seems to work now. Is this a legitimate fix? Here's the way I have the code now:
// If error, route it.
if (!err) {
return;
}
if (settings.auth) {
var credentials = auth(req);
if (!credentials || credentials.name !== settings.auth.username || credentials.pass !== settings.auth.password) {
res.statusCode = 401;
res.setHeader('WWW-Authenticate', 'Basic realm="Access Denied"');
res.end('Access denied');
return;
}
}
if (req.method === 'GET') {
api.requestHandler(req, res);
}
Sorry about the late answer. This was a good catch, what I believe happens is that the request from Sonos for fetching the TTS file, crashes the api. Your fix resolves it, but it also exposes any static file (within the static folder), including tts files etc without authentication. This might not be desirable, but is probably the best case for now.
Sonos on the other hand might handle authenticated requests if they would be part of the url, I haven't tested it.
Fixed in b588a84476f9f59a82422bedf091828b93d5f08e
It's been a few weeks since I did anything with the "say" command, and it used to work (although not 100% reliably, as there are known timing issues that I know you're working on with your rewritten base code). Anyway, today "say" is crashing node-sonos. I think the only major thing that's changed in my node-sonos since I last successfully used the "say" command is that I now have basic authentication enabled in node-sonos (because I'm using Amazon Echo to control node-sonos). Everything else except "say" seems to be working fine.
Anyway, here's a dump I get from Webstorm when I try to use the "say" command. It DOES play the message, but then node-sonos crashes. Any ideas?