Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Memory leak with inlineVolume: true #197

Open
cjh980402 opened this issue Sep 9, 2021 · 6 comments
Open

Memory leak with inlineVolume: true #197

cjh980402 opened this issue Sep 9, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@cjh980402
Copy link

cjh980402 commented Sep 9, 2021

Please describe the problem you are having in as much detail as possible:

Include a reproducible code sample here, if possible:

// Place your code here
let stream = await playdl.stream('https://www.youtube.com/watch?v=rn0wEJmoGdg')

let resource = createAudioResource(stream.stream, {
    inputType : stream.type,
    inlineVolume: true
})
let player = createAudioPlayer({
    behaviors: {
        noSubscriber: NoSubscriberBehavior.Stop
    }
})
player.play(resource)

connection.subscribe(player)

// wait 10 seconds

let connection = getVoiceConnection(message.guild.id)
let player = connection.state.subscription.player
player.stop()

// repeat above code about 5~10 times then we can see memory leak(memory usage is increased.)

Further details:

  • @discordjs/voice version: 0.6.0
  • Node.js version: 16.6.2
  • Operating system: ubuntu 20.04
  • Priority this issue should have – please be realistic and elaborate if possible:
  • Issue is memory usage is increased when inlineVolume: true for createAudioResource.
  • I can see my issue when play long song (like https://www.youtube.com/watch?v=rn0wEJmoGdg) and enable the volume (inlineVolume: true).

Relevant client options:

  • partials: none
  • gateway intents: none
  • other: none
@cjh980402 cjh980402 added the bug Something isn't working label Sep 9, 2021
@iim-ayush
Copy link
Contributor

iim-ayush commented Sep 9, 2021

You could have provided a better code for them to test :-

client.on('messageCreate', async message => {
	if(message.content.startsWith('!play')){
		await connectVC(message)
		play_loop(message)
	}
})

async function connectVC(message){
	if(!message.member.voice?.channel) return message.channel.send('Connect to a Voice Channel')
	const connection = joinVoiceChannel({
		channelId : message.member.voice.channel.id,
		guildId : message.guild.id,
		adapterCreator: message.guild.voiceAdapterCreator
	})
	
	let player = createAudioPlayer({
		behaviors: {
			noSubscriber: NoSubscriberBehavior.Play
		}
	})
	connection.subscribe(player)
}

async function play_loop(message){
	
	let stream = await playdl.stream('https://www.youtube.com/watch?v=6tyB97J1cVA&t=834s')

	let resource = createAudioResource(stream.stream, {
		inputType : stream.type,
		inlineVolume: true
	})
	
	let connection = getVoiceConnection(message.guild.id)
	let player = connection.state.subscription.player
	player.play(resource)

	setTimeout(() => {
		player.stop()
		setTimeout(() => {play_loop(message)}, 6000)
	}, 10000)
}

@iim-ayush
Copy link
Contributor

iim-ayush commented Sep 9, 2021

Audio Resource getting in that 6 seconds loop [ where I am looping play_loop() function ] :-

here

@PapiOphidian
Copy link

This seems to occur within the opus Encoder as piping audio control through FFMPEG (both prism-media's FFmpeg class and conventionally using child_process.spawn) outputting as S16LE and then piping to an opus Encoder causes the leak.

@pauldb09
Copy link

Is there any fix yet?

@PapiOphidian
Copy link

A fix lib side has not been implemented yet

A workaround is to have all voice logic in a separate worker_thread since they're their own separate v8 instance which you can destroy arbitrarily and all the resources will be freed.

@iim-ayush
Copy link
Contributor

Is there any fix yet?

Yup just uninstall discordjs opus now and start using opusscript.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants