Skip to content
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 WS_NOT_OPEN error #1

Merged
merged 2 commits into from
Mar 20, 2021
Merged

Fix WS_NOT_OPEN error #1

merged 2 commits into from
Mar 20, 2021

Conversation

knt2nd
Copy link
Owner

@knt2nd knt2nd commented Mar 20, 2021

Here is the error log.

[DEBUG] Error [WS_NOT_OPEN]: Websocket not open to send ...
at /home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:93:68
at new Promise (<anonymous>)
at VoiceWebSocket.send (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:92:12)
at VoiceWebSocket.sendPacket (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:112:17)
at VoiceConnection.setSpeaking (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/VoiceConnection.js:153:8)
at StreamDispatcher._setSpeaking (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:303:35)
at StreamDispatcher._sendPacket (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:290:10)
at StreamDispatcher._playChunk (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:253:10)
at StreamDispatcher._write (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/dispatcher/StreamDispatcher.js:107:10)
at writeOrBuffer (internal/streams/writable.js:358:12) {
[Symbol(code)]: 'WS_NOT_OPEN'
}

It comes from,

https://github.com/discordjs/discord.js/blob/8a7abc9f06d44bf693e35a615bb6ba2c3eb1d6e7/src/client/voice/networking/VoiceWebSocket.js#L90-L99

WebSocket reconnection solves the problem, but why no connection here in the first place. The answer is:

[DEBUG] [WS] closed
[DEBUG] [WS] connect requested
[DEBUG] [WS] reset requested
[DEBUG] [WS] connecting, 5 attempts, wss://japan4233.discord.media/?v=4&encoding=json
[DEBUG] [WS] opened at gateway japan4233.discord.media
...
[DEBUG] [WS] closed
[DEBUG] [WS] connect requested
[DEBUG] [WS] reset requested
[DEBUG] Error [VOICE_CONNECTION_ATTEMPTS_EXCEEDED]: Too many connection attempts (5).
at VoiceWebSocket.connect (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:67:26)
at Timeout._onTimeout (/home/kanata/projects/knt2-dbot/node_modules/discord.js/src/client/BaseClient.js:83:7)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7) {
[Symbol(code)]: 'VOICE_CONNECTION_ATTEMPTS_EXCEEDED'
}

When your bot in a voice channel for long time, days or weeks, it encounters the retry limit.

https://github.com/discordjs/discord.js/blob/8a7abc9f06d44bf693e35a615bb6ba2c3eb1d6e7/src/client/voice/networking/VoiceWebSocket.js#L66-L69

It emits the debug event only. I assume that handling at the debug event is a typical bad practice. So, I decided to reset the retry counter every 10 mins. I know it's not a good practice either but I'd say it is better. It should work in most of cases. If it didn't work, it would re-join the voice channel before playing audio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant