DPP: Bot is unable to properly connect to certain Discord voice servers

Git commit reference cd5b9cab3fb6a49ece575e0f86475268f886766b

Describe the bug The problem is that on_voice_ready callback is not called when bot connects to certain voice channels. Example of successful voice server connection:

  1. DPP logs show this: DEBUG: Sending op 4 to join VC, guild xxx channel xxx DEBUG: Connecting voice for guild xxx channel xxx DEBUG: Connecting new voice session... DEBUG: Voice websocket established; UDP endpoint: xxx.xxx.xxx.xxx:xxx [ssrc=xxx] with 7 modes DEBUG: External IP address: xxx.xxx.xxx.xxx
  2. Bot connects with following request: GET /?v=4 HTTP/1.1 Host: russia8508.discord.media pragma: no-cache User-Agent: DPP/0.1 Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Key: xxx Sec-WebSocket-Version: 13
  3. Server responds with HTTP 101 response: HTTP/1.1 101 Switching Protocols Connection: upgrade sec-websocket-accept: xxx upgrade: websocket CF-Cache-Status: DYNAMIC Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=xxx"}],"group":"cf-nel","max_age":604800} NEL: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800} Strict-Transport-Security: max-age=15552000; includeSubDomains; preload X-Content-Type-Options: nosniff Server: cloudflare CF-RAY: xxx-DME
  4. Server sends JSON payload: 1{"op":8,"d":{"v":4,"heartbeat_interval":13750.0}} Connection: upgrade sec-websocket-accept: xxx upgrade: websocket CF-Cache-Status: DYNAMIC Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=xxx"}],"group":"cf-nel","max_age":604800} NEL: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800} Strict-Transport-Security: max-age=15552000; includeSubDomains; preload X-Content-Type-Options: nosniff Server: cloudflare CF-RAY: xxx-DME
  5. Connection proceeds. on_voice_ready callback is called.

Example of erroneous voice server connection in different Discord guild:

  1. DPP logs show this: DEBUG: Sending op 4 to join VC, guild xxx channel xxx DEBUG: Connecting voice for guild xxx channel xxx Nothing happens after that.
  2. Bot connects with following request: GET /?v=4 HTTP/1.1 Host: tel-aviv10001.discord.media pragma: no-cache User-Agent: DPP/0.1 Upgrade: WebSocket Connection: Upgrade Sec-WebSocket-Key: xxx Sec-WebSocket-Version: 13
  3. Server responds with HTTP 400 response: HTTP/1.1 400 Bad request Content-Type: text/html Transfer-Encoding: chunked Connection: keep-alive Cache-Control: no-cache CF-Cache-Status: DYNAMIC Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=xxx"}],"group":"cf-nel","max_age":604800} NEL: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800} Strict-Transport-Security: max-age=15552000; includeSubDomains; preload X-Content-Type-Options: nosniff Server: cloudflare CF-RAY: xxx-DME 5a <html><body><h1>400 Bad request</h1> Your browser sent an invalid request. </body></html>
  4. By design of dpp::discord_voice_client::thread_run() function bot tries to reconnect. Steps 2 and 3 are repeated infinitely. It may be important to mention that in Discord client bot actually connects to voice channel and sits there even when HTTP 400 error occurs.

To Reproduce Issue appears to only occur when bot connects to tel-avivXXXXX.discord.media Discord voice servers. The problematic servers do work in Discord desktop clients, so I think the problem is with the library. Steps to reproduce the behavior:

  1. Connect to voice channel that is served by tel-avivXXXXX.discord.media voice server.
  2. Make the bot connect to it, for example call dpp::guild::connect_member_voice().
  3. Observe that on_voice_ready callback is never called although bot connects to voice channel in Discord UI.

Expected behavior Bot should properly connect to voice server and on_voice_ready callback should be called.

System Details:

  • Tried it on both Linux PC 5.15.90.1-microsoft-standard-WSL2 #1 SMP x86_64 x86_64 x86_64 GNU/Linux and Linux rpi4 6.1.21-v8+ #1642 SMP PREEMPT aarch64 GNU/Linux OSes.
  • Desktop Discord Client was used for testing

Some of my assumptions/terms may be wrong because I tried to get how DPP source code works manually.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 39 (27 by maintainers)

Commits related to this issue

Most upvoted comments

Can confirm this finally works. rpi4, aarch64, g++ (Debian 10.2.1-6) 10.2.1 20210110

Region          | Server            | Response
-------------------------------------------------------------
Brazil          | brazil11042       | 101 Switching Protocols
Hong Kong       | hongkong6888      | 101 Switching Protocols
India           | india4938         | 101 Switching Protocols
Japan           | japan11008        | 101 Switching Protocols
Rotterdam       | rotterdam2708     | 101 Switching Protocols
Russia          | russia4606        | 101 Switching Protocols
Singapore       | singapore11024    | 101 Switching Protocols
South Africa    | southafrica9888   | 101 Switching Protocols
Syndey          | sydney8936        | 101 Switching Protocols
US Central      | us-central4565    | 101 Switching Protocols
US East         | us-east7761       | 101 Switching Protocols
US South        | us-south5750      | 101 Switching Protocols
US West         | us-west827        | 101 Switching Protocols