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

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

Closed
1 of 9 tasks
tom0010 opened this issue Feb 18, 2022 · 2 comments · Fixed by #1185
Closed
1 of 9 tasks
Assignees
Labels
enhancement M-T: A feature request for new functionality socket-mode Version: 3x
Milestone

Comments

@tom0010
Copy link

tom0010 commented Feb 18, 2022

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.

@tom0010 tom0010 changed the title Add exception handling for socket mode - BlockingIOError: the read operation timed out Add exception handling for socket mode - BlockingIOError: Resource temporarily unavailable Feb 18, 2022
@seratch seratch added enhancement M-T: A feature request for new functionality socket-mode Version: 3x and removed untriaged labels Feb 18, 2022
@seratch seratch added this to the 3.15.1 milestone Feb 18, 2022
@seratch seratch self-assigned this Feb 18, 2022
@seratch
Copy link
Member

seratch commented Feb 18, 2022

Hi @tom0010, thanks for the suggestion again!

This is also reasonable. Since the next version, we'll change the logging to print only a single line by default while printing the stack trace only when trace_enabled is True. https://github.com/slackapi/python-slack-sdk/blob/v3.15.0/slack_sdk/socket_mode/builtin/client.py#L250-L253

@tom0010
Copy link
Author

tom0010 commented Feb 18, 2022

Thanks @seratch 👍

seratch added a commit to seratch/python-slack-sdk that referenced this issue Feb 19, 2022
seratch added a commit to seratch/python-slack-sdk that referenced this issue Feb 19, 2022
seratch added a commit that referenced this issue Feb 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality socket-mode Version: 3x
Projects
None yet
2 participants