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 Mon Oct 07 10:02 2013 CDT
* lib/channel.js: Fix several cases where an unregistered channel * lib/channel.js: Fix several cases where an unregistered channel
might attempt to make a database call which then fails. might attempt to make a database call which then fails.

View file

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

View file

@ -6,6 +6,8 @@ socket.on('connect', function () {
socket.emit('joinChannel', { name: 'test' }); socket.emit('joinChannel', { name: 'test' });
}); });
socket.on('login', testAddVideos);
socket.on('queueFail', function (msg) { socket.on('queueFail', function (msg) {
console.log(msg); console.log(msg);
}); });
@ -21,7 +23,17 @@ function testAddVideos() {
ids.push(pl[i].id); 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) { (function (i) {
setTimeout(function () { setTimeout(function () {
console.log('queue', ids[i]); console.log('queue', ids[i]);
@ -30,9 +42,7 @@ function testAddVideos() {
type: 'yt', type: 'yt',
pos: 'end' pos: 'end'
}); });
}, 1050 * i); }, 1050 * (i - 9));
})(i); })(i);
} }
} }
testAddVideos();