-
Notifications
You must be signed in to change notification settings - Fork 208
Description
Summary
After a WebSocket connection reset (e.g. WS_RECV, curl: (56)), the client enters an infinite reconnect loop. The Python process remains running but never reconnects or exits, requiring a manual restart to recover.
Reproduction Steps
- Start a selfbot using the latest
discord.py-self
with curl_cffi (default install from this repo). - Wait for a network issue, or manually disconnect your server/VPS from the internet for several seconds or minutes.
- Observe the logs: the client attempts to reconnect, with repeated "Attempting a reconnect..." and "TimeoutError" messages.
- After some time, the client remains stuck in a reconnect loop. The Python process does not exit and never fully recovers, even after network connectivity is restored.
- Only restarting the Python process (manually killing and restarting) allows the client to connect to Discord again.
Code
import discord
TOKEN = "YOUR_DISCORD_TOKEN_HERE"
class MyClient(discord.Client):
async def on_ready(self):
print(f"Logged in as {self.user}")
client = MyClient()
client.run(TOKEN)
Expected Results
After a certain number of failed reconnect attempts, or after being stuck in a reconnect loop for an extended period, the client should:
- Either exit with an error code so that a process supervisor (e.g. bash loop, systemd, docker, etc.) can restart it,
- Or fully recover and reconnect automatically once the network is available again.
The process should not remain indefinitely stuck in a reconnect loop without either recovering or exiting.
Actual Results
After a network disruption or connection reset, the client enters an infinite reconnect loop.
The Python process stays alive but never reconnects or exits, even after network connectivity is restored.
No error is raised to the parent process or shell, so external process monitors do not detect the failure.
Manual restart of the Python process is required to recover functionality.
System Information
- OS: Debian 12
- Python version: 3.11.2
- discord.py-self version: Version: 2.1.0b5165+g32958618
- curl_cffi version: Version: 0.12.0
- How did you install:
pip install -U --force-reinstall git+https://github.com/dolfies/discord.py-self.git
- Running as: selfbot
Checklist
- I have confirmed I am using unmodified discord.py-self and not the upstream discord.py.
- I am using a user token (and it isn't visible in the code).
- I have searched the open issues for duplicates.
- I have searched closed issues for resolved duplicates.
- I have confirmed the development version doesn't resolve the issue.
- I have shared the entire traceback.
Additional Information
- Running as a selfbot (aware of Discord ToS; for personal/test use).
- Restarting the Python process (via bash script or manually) always restores connection immediately.
- Issue occurs even with the minimal reproducible code above.
- Network is otherwise stable; no similar issues with other bots or services on this server.
- It would be useful to have an option for max reconnect attempts or forced process exit after prolonged reconnect loops.
Logs
2025-07-17 09:19:30,021 INFO discord.gateway Gateway received close code None and reason 'Failed to WS_RECV, curl: (56) Recv failure: Connection reset by peer. See https://curl.se/libcurl/c/libcurl-errors.html first for more details.'.
2025-07-17 09:19:30,275 INFO discord.gateway Gateway has successfully RESUMED session XXXX.
2025-07-17 09:21:32,509 INFO discord.gateway Gateway received close code None and reason 'Failed to WS_RECV, curl: (56) Recv failure: Connection reset by peer. See https://curl.se/libcurl/c/libcurl-errors.html first for more details.'.
2025-07-17 09:22:32,511 ERROR discord.client Attempting a reconnect in 1.74s
Traceback (most recent call last):
File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/gateway.py", line 371, in from_client
socket = await client.http.ws_connect(str(url))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/http.py", line 713, in ws_connect
return await self.__session.ws_connect(url, headers=headers, interface=interface, timeout=30.0, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/curl_cffi/requests/session.py", line 887, in ws_connect
curl = await self.pop_curl()
^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/curl_cffi/requests/session.py", line 764, in pop_curl
curl = await self.pool.get()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/queues.py", line 158, in get
await getter
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/client.py", line 979, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
TimeoutError
2025-07-17 09:23:34,263 ERROR discord.client Attempting a reconnect in 3.35s
Traceback (most recent call last):
File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/gateway.py", line 371, in from_client
socket = await client.http.ws_connect(str(url))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/http.py", line 713, in ws_connect
return await self.__session.ws_connect(url, headers=headers, interface=interface, timeout=30.0, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/curl_cffi/requests/session.py", line 887, in ws_connect
curl = await self.pop_curl()
^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/curl_cffi/requests/session.py", line 764, in pop_curl
curl = await self.pool.get()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/queues.py", line 158, in get
await getter
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/client.py", line 979, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
TimeoutError
[CUT MANY RECONNECTS TRIES]
2025-07-17 15:00:22,600 ERROR discord.client Attempting a reconnect in 205.84s
Traceback (most recent call last):
File "/usr/lib/python3.11/asyncio/tasks.py", line 490, in wait_for
return fut.result()
^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/gateway.py", line 371, in from_client
socket = await client.http.ws_connect(str(url))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/http.py", line 713, in ws_connect
return await self.__session.ws_connect(url, headers=headers, interface=interface, timeout=30.0, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/curl_cffi/requests/session.py", line 887, in ws_connect
curl = await self.pop_curl()
^^^^^^^^^^^^^^^^^^^^^
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/curl_cffi/requests/session.py", line 764, in pop_curl
curl = await self.pool.get()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/queues.py", line 158, in get
await getter
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/root/discord-selfbot/venv/lib/python3.11/site-packages/discord/client.py", line 979, in connect
self.ws = await asyncio.wait_for(coro, timeout=60.0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/asyncio/tasks.py", line 492, in wait_for
raise exceptions.TimeoutError() from exc
TimeoutError