Cog-Creators / Cog-Creators/Red-DiscordBot
Incorrect Disconnect Handling
- Dominant language
- Python
- Stars
- 5.7k
- Forks
- 2.5k
- Avg merge
- 6d 16h
- Merged PRs (30d)
- 1
Description
### What Red version are you using?
3.4.12
### What were you trying to do?
Restart the bot
### What did you expect to happen?
Bot should restart and only resume real active players, or if no one was using it don't join or send any messages.
### What actually happened?
When the bot restarts, it joins the last channels that it was connected in every server, sends an Auto Play started message then leaves
### How can we reproduce this error?
Disconnects triggered by empty disconnect timeout don't terminate correctly Lavalink players. When the discord bot leaves the channel, Lavalink receives the following: "stop" command, then "destroy" command, then "play" command. Also the bot send the message "Auto Play Started".
This causes the following:
-When [p]restart is issued, after the bot starts, connects to the last voice channel joined and sends a message in the last text channel with "Auto Play started.", then leaves. (This is consistent behavior with Auto Play enabled after the queue ends and empty disconnect timer)
-When [p]audioset restart, after the bot starts, connects to the last voice channel joined and sends a message in the last text channel with "Auto Play started.", then leaves. (This is consistent behavior with Auto Play enabled after the queue ends and empty disconnect timer)
**Red Bot has the following starting log:**
[2021-07-28 03:04:45] [INFO] red.cogs.Audio.cog.Tasks.startup: Restored >>,
[2021-07-28 03:05:00] [INFO] red.Audio.WS.RLL: Received voice disconnect from discord, removing player.
**Lavalink has the following log:**
2021-07-28 00:04:40.283 INFO 1 --- [ XNIO-1 task-7] l.server.io.HandshakeInterceptorImpl : Incoming connection from /172.20.0.2:45086,
2021-07-28 00:04:40.287 INFO 1 --- [ XNIO-1 task-7] lavalink.server.io.SocketServer : Connection successfully established from /172.20.0.2:45086,
2021-07-28 00:04:40.288 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "configureResuming", "key": "Red-Core-Audio-824755869132390400-docker", "timeout": 60},
2021-07-28 00:04:45.340 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "play", "guildId": "837659021782810645", "track": "", "noReplace": false, "startTime": "0", "pause": false},
2021-07-28 00:04:46.003 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "voiceUpdate", "guildId": "837659021782810645", "sessionId": "489723cef01ca534d4afe1011c10ee32", "event": {"token": "b79e7f7a2818ae3e", "guild_id": "837659021782810645", "endpoint": "russia7442.discord.media:443"}},
2021-07-28 00:05:00.280 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "stop", "guildId": "837659021782810645"},
2021-07-28 00:05:00.281 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "destroy", "guildId": "837659021782810645"},
2021-07-28 00:05:00.386 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "play", "guildId": "837659021782810645", "track": "", "noReplace": false, "startTime": "0", "pause": false}
**(Last three lines are the exact behavior of empty disconnect disconnects)**
**If the bot is disconnected using [p]disconnect the above things occur.**
Disconnecting the bot using the Discord Disconnect button correctly terminates Lavalink player, but after a bot restart the same behavior occurs, but with some differences:
**Red Logs:**
[2021-07-28 02:53:16] [INFO] red.cogs.Audio.cog.Tasks.startup: Restored >>
**Lavalink Logs:**
2021-07-28 00:14:05.738 INFO 1 --- [ XNIO-1 I/O-2] lavalink.server.io.SocketServer : {"op": "play", "guildId": "837659021782810645", "track": "", "noReplace": false, "startTime": "0", "pause": false}, **(play track)**
2021-07-28 00:14:16.073 INFO 1 --- [ XNIO-1 I/O-2] lavalink.server.io.SocketServer : {"op": "destroy", "guildId": "837659021782810645"}, **(press discord disconnect button)**
2021-07-28 00:14:24.196 INFO 1 --- [ XNIO-1 I/O-2] lavalink.server.io.SocketServer : {"op": "configureResuming", "key": null}, **(restart command)**
2021-07-28 00:14:24.199 INFO 1 --- [ XNIO-1 I/O-2] lavalink.server.io.SocketServer : Connection closed from /172.20.0.2:45396 -- CloseStatus[code=1000, reason=], **(restart command)**
2021-07-28 00:14:24.199 INFO 1 --- [ XNIO-1 I/O-2] lavalink.server.io.SocketContext : Shutting down 0 playing players., **(restart command)**
2021-07-28 00:14:41.484 INFO 1 --- [ XNIO-1 task-11] l.server.io.HandshakeInterceptorImpl : Incoming connection from /172.20.0.2:45666, **(restart command)**
2021-07-28 00:14:41.487 INFO 1 --- [ XNIO-1 task-11] lavalink.server.io.SocketServer : Connection successfully established from /172.20.0.2:45666, **(restart command)**
2021-07-28 00:14:41.488 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "configureResuming", "key": "Red-Core-Audio-824755869132390400-docker", "timeout": 60}, **(restart command)**
2021-07-28 00:14:46.734 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "voiceUpdate", "guildId": "837659021782810645", "sessionId": "ed8de63964c7bf4c3c37c937a7ade4c4", "event": {"token": "2f350c9797948ac0", "guild_id": "837659021782810645", "endpoint": "eu-central1396.discord.media:443"}}, **(bot joins then...)**
2021-07-28 00:14:46.542 INFO 1 --- [ XNIO-1 I/O-4] lavalink.server.io.SocketServer : {"op": "play", "guildId": "837659021782810645", "track": "": false, "startTime": "0", "pause": false} (bot requests a song then leaves because of the empty disconnect timer doing the original behavior "when disconnecting it stops and destroys the player, then starts another one and send message Auto Play Started message.)
### Anything else?
If you need more details or a demo my discord is rtemelcea#6348 .
Contributor guide
Assessment
This issue has not been assessed yet.