Skip to content

fix: VoiceGateway connection is closed with code 4020 #1727

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

Merged

Conversation

SirTurlock
Copy link
Contributor

@SirTurlock SirTurlock commented Aug 5, 2024

Pull Request Type

  • Feature addition
  • Bugfix
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

The heartbeat sent to the VoiceGateway used random.uniform(0.0, 1.0) to generate a nonce. A recent change in the Discord backend causes it to reject a float value and close the connection with code 4020. The backend now expects an uint64.

Changes

  • changed random.uniform(0.0, 1.0) to random.getrandbits(64) in send_heartbeat to generate an uint64 instead of a float.

Related Issues

Fixes #1726

Test Scenarios

None.

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x
  • I've ensured my code works on Python 3.12.x

Checklist

  • I've run the pre-commit code linter over all edited files (ran manually)
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

…t is sent

Fixes interactions-py#1726
VoiceGateway no longer accepts a string or a float in the heartbeat nonce and instead immediately disconnects the client with code 4020.
Fixed send_heartbeat to use an uint64 instead of a float for the nonce.
@SirTurlock
Copy link
Contributor Author

SirTurlock commented Aug 6, 2024

Discord has since acknowledged the issue and reverted the change so this is now kinda redundant, but it may be a bit more future-proof this way (technically uint64 is the accepted value) and better matches the example in the documentation.

@donkevlar
Copy link

Note that I am getting this error repeatedly even though its reportedly 'reverted' on the discord API.

Task exception was never retrieved
future: <Task finished name='Task-458' coro=<ActiveVoiceState._ws_connect() done, defined at /usr/local/lib/python3.12/site-packages/interactions/models/internal/active_voice_state.py:105> exception=VoiceWebSocketClosed('The Websocket closed with code: 4020 - Unknown Error')>
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/interactions/models/internal/active_voice_state.py", line 109, in _ws_connect
    await self.ws.run()
  File "/usr/local/lib/python3.12/site-packages/interactions/api/voice/voice_gateway.py", line 85, in run
    msg = await receiving
          ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/interactions/api/voice/voice_gateway.py", line 121, in receive
    raise VoiceWebSocketClosed(resp.data)
interactions.client.errors.VoiceWebSocketClosed: The Websocket closed with code: 4020 - Unknown Error

@SirTurlock
Copy link
Contributor Author

SirTurlock commented Aug 8, 2024

I may have been a bit hasty when I said it was redundant. I double checked just right now and the exact words from the Discord staff guy was:

or JS 64-bit integer reasons we're now rolling out a change that'll let you send the strings again

So, I'm guessing this fix is not at all redundant, because the lib is sending a float. :/
I'm assuming here that it now accepts integer and string, but not float, but I can't test it right now.

@AstreaTSS AstreaTSS mentioned this pull request Aug 12, 2024
@AstreaTSS AstreaTSS merged commit 33f8bdf into interactions-py:unstable Aug 12, 2024
1 check passed
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.

3 participants