Repository: discordjs/discord.js

Issue #1693: .playFile() & .playStream() delays
Created: 2017-07-17T10:41:32Z
First of all, I am not quite sure if this has something to do with versions stuff, and I think it is an issue, and yes this is my first time doing this, and yes I have been asking for several days in the support server, but no one seems to figure it out so I have decided to post it here, if this is not an issue then I am so sorry.
Issue: If a bot is playing songs, when a song ends, the .playFile() delays, at first it does not delay but after a lot of songs, it can delay for up to 2 minutes(according to what I've only experienced), the duration of delay increases more and more after each song. According to what I've been experimenting it might not be because of my code, and yes I am still a noob, even though I've been coding with Discord.JS for like 7 months.
Additional information (Mostly assumption):
i) The delays are differentiated in each server, even though the bot has delayed a lot in a server, but if you play in another server it'll play immediately.
ii) Messages sent before the delays, which kinda means it has nothing to do with CPU usage or whatever.
Further details:
Discord.JS version: 11.1.0
Node.JS version: 8.0.0
Operating system: Ubuntu

Duplicate issue #2017: Dispatchers taking a long time to start in VoiceConnections where one has already played
Created: 2017-10-08T21:55:09Z
Please describe the problem you are having in as much detail as possible:
I'm dynamically creating dispatchers in the same voice connection to play an ogg vorbis sound when necessary. There is never more than one dispatcher at the same time. However, I'm noticing a correlation between the number of times a dispatcher has played and the time it takes for new ones to actually start emitting sound.
Include a reproducible code sample here, if possible:
_doNext() {
	console.log(`[Debug] _doNext`);
	this.voiceQueueRunning = false;

	if (!this.voiceQueue.length)
		return;

	let buffer = Buffer.concat(this.voiceQueue);
	if (!buffer)
		return;
		
	this.voiceQueue = [];

	const connection = this.voiceChannel.connection;
	if (!connection)
		return;

	this.voiceQueueRunning = true;

	const dispatcher = connection.playStream(new Readable({
		read() {
			this.push(buffer);
			buffer = null;
		}
	}));
	console.log(`[Debug] connection.playStream`);

	dispatcher.on('end', (reason) => {
		console.log(`[Debug] Ended, reason: ${reason}`);
		if (reason == 'Stream is not generating quickly enough.') {
			setTimeout(() => {
				this._doNext();
			}, 100);
		} else if (reason) {
			//bot-specific stuff
		}
	});

	dispatcher.on('error', console.error);
}
Further details:
"[Debug] connection.playStream" prints to the console the instant it should, but it can take upwards of 40 seconds before the bot starts sending voice data, starting at no delay and increasing over time.

discord.js version: 11.2.1
node.js version: 8.6.0
Operating system: Ubuntu 16.04 xenial
Priority this issue should have – please be realistic and elaborate if possible: low



 I found this issue while running code on a user account
 I have also tested the issue on latest master, commit hash:

Closing comment (2017-10-09T00:21:01Z): this issue is related to #1693 and you can find a temporary workaround in there also its already fixed on master with the commit #1745