-
Notifications
You must be signed in to change notification settings - Fork 417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix for a rare FFMPEG stream closing error #451
base: dev
Are you sure you want to change the base?
Conversation
set high watermark to max 32bit int to fix a rare stream closing issue
Can confirm, also happens with other Discord libs like discord.js. I was debugging this for a few nights with Linkjay, and oddly enough it was only happening to me at first -- even with both of us testing on multiple machines. We even tried sending eachother our entire node_modules folders. Not sure what changed that it's happening for him now too. I could repro this on multiple machines, on multiple distros, multiple versions of node, while using old library versions, with or without ytdl-core (even while using a manual ffmpeg child_process). This only started happening about a month ago. Would be nice to figure out why this is suddenly happening, but for now this fixes it. My understanding is that the child process should pause writing to the stdout stream once it has enough buffered to meet highWaterMark (in bytes), to allow the reading end of the stream to catch up, but it isn't for some reason. I couldn't figure out any reason why. Bumping up highWaterMark to the max allowed number (max 32bit int) seems to resolve the issue as the buffer simply won't get full anymore, and the full output of ffmpeg can be stored. Simple code we used to test: eristest.tar.gz |
Thanks for doing the investigative work here! Possibly one cause of #213, along with a couple other reported WTFs. Code-wise, comments should follow capitalization and spelling like the rest of the lib. More importantly though, nullifying |
I'm open to being wrong here, but I don't think that is true when it comes to the memory implications. I'm running my bot on a 2 GB RAM VPS and tested out a lot of different 10 - 30 minute videos and a 3 hour video with no memory implications. I and Doug have been running our bots (his on discord.js with special ffmpeg; mine with eris and hard coded highwatermark in the library) just fine with this fix. I'll continue to test and see if I can run into these memory issues that you say, but I believe this is a fix. I will add another commit making my code consistent with the rest of the library. Also, the integer we used in this commit is actually |
There is an issue on some systems where an FFMPEG stream will close and stop the song at some duration throughout.
Upon further investigation, it appears that the stdout buffer that FFMPEG reads from the network stream is reading more than is available and stops entirely. (something like that)
To fix this, bumping up the highWaterMark variable to the highest number possible will remove this issue.
It's hard to test this issue. Basically, it appears as if nothing is wrong for some people on any system. Anybody can just play what they want. Then, by pure luck, everything from there on out will stop halfway through. It's got to be some system-level thing that is going wrong, but this fixes it.
We've tested this on multiple different bots with different libraries and they work just fine with this fix.