Skip to content

Add exception handling for socket mode - BlockingIOError: Resource temporarily unavailable #1184

@tom0010

Description

@tom0010

This is very similar to #1181.
I'd like to also add another exception handler as I am also frequently getting BlockingIOError which is unnecessary and is filling up logs.
Please see the trace below.

2022-02-18 08:31:57.486 | ERROR    | slack_sdk.socket_mode.builtin.client:_on_error:249 - on_error invoked (session id: 45b057d3-700c-4ea3-a932-ee829cb1f2d8, error: BlockingIOError, message: [Errno 11] Resource temporarily unavailable)Traceback (most recent call last):

  File "/usr/local/lib/python3.9/threading.py", line 930, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x7fb7f5607b80><Thread(Thread-1, started daemon 140428008782640)>
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x7fb7f56078b0><Thread(Thread-1, started daemon 140428008782640)>
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(Thread-1, started daemon 140428008782640)>
    │    │        │    └ ()
    │    │        └ <Thread(Thread-1, started daemon 140428008782640)>
    │    └ <bound method IntervalRunner._run of <slack_sdk.socket_mode.interval_runner.IntervalRunner object at 0x7fb7f19f8370>><Thread(Thread-1, started daemon 140428008782640)>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/interval_runner.py", line 19, in _run
    self.target()
    │    └ <bound method SocketModeClient._run_current_session of <slack_sdk.socket_mode.builtin.client.SocketModeClient object at 0x7fb...
    └ <slack_sdk.socket_mode.interval_runner.IntervalRunner object at 0x7fb7f19f8370>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/client.py", line 277, in _run_current_session
    self.current_session.run_until_completion(self.current_session_state)
    │    │               │                    │    └ <slack_sdk.socket_mode.builtin.connection.ConnectionState object at 0x7fb7f1287940>
    │    │               │                    └ <slack_sdk.socket_mode.builtin.client.SocketModeClient object at 0x7fb7f19de730>
    │    │               └ <function Connection.run_until_completion at 0x7fb7f2eae1f0>
    │    └ <slack_sdk.socket_mode.builtin.connection.Connection object at 0x7fb7f1095a30><slack_sdk.socket_mode.builtin.client.SocketModeClient object at 0x7fb7f19de730>
> File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/connection.py", line 311, in run_until_completion
    ] = _receive_messages(
        └ <function _receive_messages at 0x7fb7f2ea59d0>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 218, in _receive_messages
    return _fetch_messages(
           └ <function _fetch_messages at 0x7fb7f2ea5a60>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 241, in _fetch_messages
    remaining_bytes = receive()  # type: ignore<function _receive_messages.<locals>.receive at 0x7fb7f0a75b80>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 216, in receive
    raise e
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 205, in receive
    received_bytes = sock.recv(size)
                     │    │    └ 1024
                     │    └ <function SSLSocket.recv at 0x7fb7f4c61b80><ssl.SSLSocket fd=14, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 55220), raddr=...
  File "/usr/local/lib/python3.9/ssl.py", line 1226, in recv
    return self.read(buflen)
           │    │    └ 1024
           │    └ <function SSLSocket.read at 0x7fb7f4c61430><ssl.SSLSocket fd=14, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 55220), raddr=...
  File "/usr/local/lib/python3.9/ssl.py", line 1101, in read
    return self._sslobj.read(len)
           │    │       │    └ 1024
           │    │       └ <method 'read' of '_ssl._SSLSocket' objects>
           │    └ <_ssl._SSLSocket object at 0x7fb7f142d510><ssl.SSLSocket fd=14, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 55220), raddr=...

BlockingIOError: [Errno 11] Resource temporarily unavailable
2022-02-18 08:31:57.561 | INFO     | slack_sdk.socket_mode.builtin.connection:disconnect:186 - The connection has been closed (session id: 45b057d3-700c-4ea3-a932-ee829cb1f2d8)

You can see that there is a log message that says the session has been disconnected, which is fine, that's all I need really, I don't need to see the full trace.

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.models (UI component builders)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.rtm (RTM client)
  • slack_sdk.signature (Request Signature Verifier)

Requirements

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions