serenity-rs / songbird

An async Rust library for the Discord voice API
ISC License
384 stars 110 forks source link

Input: Fix high CPU use when initialising long files over HTTP #163

Closed FelixMcFelix closed 1 year ago

FelixMcFelix commented 1 year ago

Fixes the possibility of a spinlock while reading bytes from an async->sync adapter. This case can be observed with long (e.g., 10 hours of silence) videos which seem to be served slower than we would like to parse their headers.

The fix moves most communication to blocking: read calls first parse all messages form the async context in a non-blocking way, then swap to blocking if no bytes are available.

Tested using cargo make ready and "examples/serenity/voice" against the URL https://www.youtube.com/watch?v=g4mHPeMGTJM.