Skip to content
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

Failed to receive or enqueue a message: TypeError, object of type 'ServerTimeoutError' has no len() #1622

Open
lingfish opened this issue Dec 22, 2024 · 4 comments
Labels
area:async bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x
Milestone

Comments

@lingfish
Copy link

I'm seeing similar to #1458. My log though says:

Failed to receive or enqueue a message: TypeError, object of type 'ServerTimeoutError' has no len() (s_7940572168521)

The ServerTimeoutError I think is coming from aiohttp.

I believe it is related to this exception:

ClientConnectionResetError: Cannot write to closing transport
  File "aiohttp/_websocket/writer.py", line 125, in send_frame
    raise ClientConnectionResetError("Cannot write to closing transport")

Reproducible in:

slack_bolt         1.21.2
slack_sdk          3.33.4

Python 3.11.2

#1 SMP PREEMPT_DYNAMIC PMX 6.8.12-1 (2024-08-05T16:17Z)

The Slack SDK version

As above.

Python runtime version

As above.

OS info

As above.

Steps to reproduce:

    handler = AsyncSocketModeHandler(app, settings.slack.slack_app_token)
    await handler.connect_async()

Actual result:

As above.

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. 🙇

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

@lingfish lingfish changed the title (Set a clear title describing the issue) Failed to receive or enqueue a message: TypeError, object of type 'ServerTimeoutError' has no len() Dec 22, 2024
@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x socket-mode area:async and removed untriaged labels Dec 23, 2024
@seratch seratch added this to the 3.x milestone Dec 23, 2024
@seratch
Copy link
Member

seratch commented Dec 23, 2024

Hi @lingfish, thanks for reporting this issue. I am still unsure why this could happen in the code yet (message_data in the code cannot be an exception, this is the confusion I'm having), but once our team figures the cause out, changes to resolve it would be included in future releases.

@WilliamBergamin
Copy link
Contributor

🤔 This seems like an odd one, from what I can tell the error was caught in the exception block but this seems to an aiohttp ServerTimeoutError

From what I can gather error comes up when the connection with the server is established, but some reading from socket takes too long. (source)

I tried reproducing this behavior in a unit test but wasn't able to 🤔

@lingfish is there any more stack-trace you could share with us? I'm having a hard time figuring out where len() may be called on ServerTimeoutError

@WilliamBergamin
Copy link
Contributor

@seratch #1620 may be able to help figure out if we are calling len() on an exception

@lingfish
Copy link
Author

Yeah, I've been struggling for days now to try to trigger this via tests, to no avail.

BUT! I decided to literally break the network using a blackhole route, and I modified the exception block to actually log an exception, and here it is:

2024-12-24 10:52:49,998 ERROR __main__ Failed to receive or enqueue a message: TypeError, object of type 'ServerTimeoutError' has no len() (s_8788050674129)
2024-12-24 10:52:50,021 ERROR __main__ object of type 'ServerTimeoutError' has no len()
Traceback (most recent call last):
  File "/srv/virtualenv/fishbot-oMssWodV/lib/python3.11/site-packages/slack_sdk/socket_mode/aiohttp/__init__.py", line 244, in receive_messages
    if message_data is not None and len(message_data) > 0:
                                    ^^^^^^^^^^^^^^^^^
TypeError: object of type 'ServerTimeoutError' has no len()

Not sure about the decision to not re-raise exceptions in slack_sdk? And catching Exception is a no-no, isn't it (kinda for these reasons)?

So it happens here.

Putting in a little logging with a type() call, this is the whole output now:

2024-12-24 11:23:37,998 INFO __main__ <class 'aiohttp.client_exceptions.ServerTimeoutError'>
2024-12-24 11:23:37,998 ERROR __main__ Failed to receive or enqueue a message: TypeError, object of type 'ServerTimeoutError' has no len() (s_8729441075225)
2024-12-24 11:23:38,031 ERROR __main__ object of type 'ServerTimeoutError' has no len()
Traceback (most recent call last):
  File "/srv/virtualenv/fishbot-oMssWodV/lib/python3.11/site-packages/slack_sdk/socket_mode/aiohttp/__init__.py", line 246, in receive_messages
    if message_data is not None and len(message_data) > 0:
                                    ^^^^^^^^^^^^^^^^^
TypeError: object of type 'ServerTimeoutError' has no len()

Hopefully this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:async bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x
Projects
None yet
Development

No branches or pull requests

3 participants