From 65232c38702be5844cf2ce865a4777eb1928b5d0 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Tue, 1 Sep 2026 05:17:34 -0400 Subject: [PATCH] Reconnect the gateway with the default URL during 500s Fix #10511 --- discord/gateway.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/discord/gateway.py b/discord/gateway.py index 47b485c86..c377ee46e 100644 --- a/discord/gateway.py +++ b/discord/gateway.py @@ -390,7 +390,19 @@ class DiscordWebSocket: v=INTERNAL_API_VERSION, encoding=encoding, compress=utils._ActiveDecompressionContext.COMPRESSION_TYPE ) - socket = await client.http.ws_connect(str(url)) + try: + socket = await client.http.ws_connect(str(url)) + except aiohttp.WSServerHandshakeError as e: + # If the server errors out while connecting while under a non-default URL + # due to resume_gateway_url, then fallback to the older default + # See #10511 + if e.status >= 500 and gateway != cls.DEFAULT_GATEWAY: + socket = await client.http.ws_connect(str(cls.DEFAULT_GATEWAY)) + gateway = cls.DEFAULT_GATEWAY + resume = False + else: + raise e + ws = cls(socket, loop=client.loop) # dynamically add attributes needed