Fix the only thing I see that could possibly still cause #285

This commit is contained in:
calzoneman 2013-10-07 19:03:20 -05:00
parent f5cbdb2f24
commit a3153246ce
3 changed files with 40 additions and 27 deletions

View file

@ -1,3 +1,10 @@
Mon Oct 07 19:00 2013 CDT
* lib/channel.js: Rearrange the callback order to prevent database
lookups from racing with the playlist queue.
* tests/naokosimulator2013.js: Flood the first 10 videos all at once.
Should provide better test coverage for race conditions (especially
on localhost where the latency is ~0)
Mon Oct 07 10:02 2013 CDT
* lib/channel.js: Fix several cases where an unregistered channel
might attempt to make a database call which then fails.

View file

@ -1523,37 +1523,33 @@ Channel.prototype.addMedia = function(data, user) {
});
});
} else {
self.server.db.getLibraryItem(self.name, data.id,
function (err, item) {
self.plqueue.queue(function (q) {
if (self.dead)
return;
self.server.db.getLibraryItem(self.name, data.id,
function (err, item) {
if (self.dead)
return;
if (err) {
user.socket.emit("queueFail", {
msg: "Internal error: " + err,
link: $util.formatLink(data.id, data.type)
});
return;
}
if (item !== null) {
if (data.maxlength && item.seconds > data.maxlength) {
if (err) {
user.socket.emit("queueFail", {
msg: "Media is too long!",
link: $util.formatLink(item.id, item.type)
msg: "Internal error: " + err,
link: $util.formatLink(data.id, data.type)
});
return;
}
self.plqueue.queue(function (q) {
if (self.dead)
if (item !== null) {
if (data.maxlength && item.seconds > data.maxlength) {
user.socket.emit("queueFail", {
msg: "Media is too long!",
link: $util.formatLink(item.id, item.type)
});
return;
}
afterData.bind(self, q, true)(item);
});
} else {
self.plqueue.queue(function (q) {
if (self.dead)
return;
} else {
self.server.infogetter.getMedia(data.id, data.type,
function (e, m) {
if (self.dead)
@ -1569,8 +1565,8 @@ Channel.prototype.addMedia = function(data, user) {
afterData.bind(self, q, false)(m);
});
});
}
}
});
});
}
};

View file

@ -6,6 +6,8 @@ socket.on('connect', function () {
socket.emit('joinChannel', { name: 'test' });
});
socket.on('login', testAddVideos);
socket.on('queueFail', function (msg) {
console.log(msg);
});
@ -21,7 +23,17 @@ function testAddVideos() {
ids.push(pl[i].id);
}
for (var i = 0; i < ids.length; i++) {
// burst the first 10
for (var i = 0; i < 10; i++) {
console.log('queue', ids[i]);
socket.emit('queue', {
id: ids[i],
type: 'yt',
pos: 'end'
});
}
for (var i = 10; i < ids.length; i++) {
(function (i) {
setTimeout(function () {
console.log('queue', ids[i]);
@ -30,9 +42,7 @@ function testAddVideos() {
type: 'yt',
pos: 'end'
});
}, 1050 * i);
}, 1050 * (i - 9));
})(i);
}
}
testAddVideos();