dolfies / discord.py-self

A fork of the popular discord.py for user accounts.
https://discordpy-self.rtfd.io/en/latest/
MIT License
680 stars 161 forks source link

Slash command execution timeout #380

Closed jbaumgarten closed 1 year ago

jbaumgarten commented 1 year ago

Summary

When I am using a slash command, it is successfully executed but it generates a timeout which stop the bot

Reproduction Steps

First create a client self-bot Then execute a slash command

Code

No response

Expected Results

The slash command should be executed without any exception

Actual Results

2022-09-14 19:42:43,569 [INFO] - Timed out receiving packet. Attempting a reconnect.
2022-09-14 19:42:43,570 [INFO] - Got a request to RESUME the websocket.
2022-09-14 19:42:43,571 [WARNING] - Gateway has stopped responding. Closing and restarting.
2022-09-14 19:42:43,754 [INFO] - Gateway has sent the RESUME payload.
2022-09-14 19:42:43,861 [INFO] - Gateway session has been invalidated.
2022-09-14 19:42:43,971 [INFO] - Got a request to IDENTIFY the websocket.
2022-09-14 19:42:44,118 [INFO] - Gateway has sent the IDENTIFY payload.
2022-09-14 19:42:44,721 [INFO] - Connected to Gateway: ["gateway-prd-main-sm1f",{"micros":284464,"calls":["id_created",{"micros":451,"calls":[]},"session_lookup_time",{"micros":2220,"calls":[]},"session_lookup_finished",{"micros":16,"calls":[]},"discord-sessions-blue-prd-2-39",{"micros":270722,"calls":["start_session",{"micros":83276,"calls":["discord-api-d6c79f597-b4m8j",{"micros":73772,"calls":["get_user",{"micros":13930},"get_guilds",{"micros":21560},"user_settings_proto",{"micros":109},"relationships",{"micros":28198},"friend_suggestion",{"micros":59},"connections",{"micros":14},"serialized_read_states",{"micros":5},"pending_payments",{"micros":1},"send_scheduled_deletion_message",{"micros":1},"sanitize_premium_perks",{"micros":1},"guild_join_requests",{"micros":1},"user_guild_settings",{"micros":1},"serialized_private_channels",{"micros":1},"experiments",{"micros":4517},"affine_user_ids",{"micros":484},"required_action",{"micros":4},"authorized_ip_coro",{"micros":2}]}]},"starting_guild_connect",{"micros":80,"calls":[]},"presence_started",{"micros":29269,"calls":[]},"guilds_started",{"micros":135076,"calls":[]},"guilds_connect",{"micros":6466,"calls":[]},"presence_connect",{"micros":1,"calls":[]},"connect_finished",{"micros":6487,"calls":[]},"build_ready",{"micros":9645,"calls":[]},"optimize_ready",{"micros":2647,"calls":[]},"split_ready",{"micros":4220,"calls":[]},"clean_ready",{"micros":19,"calls":[]}]}]}] (Session ID: afa664dea255b051369d462ceba486e3).
Ignoring exception in on_ready
Traceback (most recent call last):
  File "/root/anaconda3/envs/testdiscord/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
    return fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/root/anaconda3/envs/testdiscord/lib/python3.10/site-packages/discord/client.py", line 395, in _run_event
    await coro(*args, **kwargs)
  File "/root/python/test/main.py", line 96, in on_ready
    await command(user=toto)
  File "/root/anaconda3/envs/testdiscord/lib/python3.10/site-packages/discord/commands.py", line 615, in __call__
    return await super().__call__(*self._parse_kwargs(kwargs), channel)
  File "/root/anaconda3/envs/testdiscord/lib/python3.10/site-packages/discord/commands.py", line 261, in __call__
    return await super().__call__(data, files, channel)
  File "/root/anaconda3/envs/testdiscord/lib/python3.10/site-packages/discord/commands.py", line 128, in __call__
    i = await state.client.wait_for(
  File "/root/anaconda3/envs/testdiscord/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

### System Information

(testdiscord) root@vm5-18:~# python -m discord -v

Checklist

Additional Information

No response

theAbdoSabbagh commented 1 year ago

can confirm, happens with me too

ThePrivatePanda commented 1 year ago

That specefically looks like an issue at startup, could you please share some test code/test case?

dolfies commented 1 year ago

For anyone interested, the cause of this seems to be the gateway closing at an inopportune time, causing the interaction wait_for() (which usually wouldn't take more than 3 seconds) to timeout while the gateway RESUMEs. I've increased the timeout (and caught the right TimeoutError (oops)) to account for this edge-case.

The actual solution to this would be eliminating the bad/blocking code or network problem that causes the gateway to reconnect as often as it is in these issues.

jbaumgarten commented 1 year ago

For anyone interested, the cause of this seems to be the gateway closing at an inopportune time, causing the interaction wait_for() (which usually wouldn't take more than 3 seconds) to timeout while the gateway RESUMEs. I've increased the timeout (and caught the right TimeoutError (oops)) to account for this edge-case.

The actual solution to this would be eliminating the bad/blocking code or network problem that causes the gateway to reconnect as often as it is in these issues.

Hi guy, thx for your change. I fogot to update the issue but in my case, I had a sleep in my code which was not using asyncio library. Once I changed it to use asyncio.sleep, I had less gateway disconnect/reconnect :)