Skip to content

websocket does not resume #819

@AnthonyZJiang

Description

@AnthonyZJiang

Summary

websocket does not resume after closure

Reproduction Steps

I wrote a simple code to monitor incoming messages from a few servers and pass them to a discord bot for reposting. The selfcord code only receives message and the discord bot only reposts messages. My code worked fine until recently (1-2 weeks ago).

Normally the bot runs fine for a few hours but at some point gateway stops responding and closes. Most of the time, it can resume but, as a rough estimate, 1 out of 5 times it does not resume and stops there with no further log output, and surely no longer connected. I had to restart the bot to get it working again.

There is no exception or all raised ones are captured in try/except block, so no traceback. I will see if I can log debug in a log file.

Code

import selfcord

from .sender import MessageSender

class MessageReceiver(selfcord.Client):
    def __init__(self, channels: list, sender: MessageSender):
        super().__init__()
        self.channels = channels
        self.sender = sender
            
    async def on_message(self, message: selfcord.Message):
        if message.channel.id not in self.channels:
            return
        self.sender.forward_message(message)

Expected Results

Closing websocket with code 4000
2025-04-21 22:16:46 INFO     selfcord.gateway Finished closing websocket
2025-04-21 22:16:47 INFO     selfcord.gateway Gateway has successfully RESUMED session *********************.

Actual Results

2025-04-22 00:15:43 WARNING  selfcord.gateway Gateway has stopped responding. Closing and restarting.
2025-04-22 00:15:43 INFO     selfcord.gateway Closing websocket with code 4000
2025-04-22 00:15:43 INFO     selfcord.gateway Finished closing websocket

System Information

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

I can confirm my internet is running 24x7 as the message sender is online all the time. The sender's websocket also closes occasionally, but oddly not the same time and way less frequent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions