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 - socket.timeout: the read operation timed out #1181

Closed
1 of 4 tasks
tom0010 opened this issue Feb 17, 2022 · 5 comments · Fixed by #1182
Closed
1 of 4 tasks
Assignees
Labels
enhancement M-T: A feature request for new functionality socket-mode
Milestone

Comments

@tom0010
Copy link

tom0010 commented Feb 17, 2022

I run socket mode with 5 sockets, which works fine, however sometimes I get a timeout, and it gives me a full traceback about socket.timeout.
I'm fine with it right now, as it just opens a new socket connection, however in the logs I'm getting a full traceback.
Are we able to handle this a bit better as it's causing a large amount of logs?
Really I don't care about this, that's why I'd like to just send a message saying it timed out and to continue working, which is why I'd like to handle this better.
This is also related to slackapi/bolt-python#529

2022-02-17 03:38:43.518 | ERROR    | slack_sdk.socket_mode.builtin.connection:connect:172 - Failed to establish a connection (session id: d63dd25a-3b4c-4306-a5ac-b3ccabde0ee6, error: The read operation timed out)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-2, started daemon 140428006546224)>
  File "/usr/local/lib/python3.9/threading.py", line 973, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x7fb7f56078b0><Thread(Thread-2, started daemon 140428006546224)>
  File "/usr/local/lib/python3.9/threading.py", line 910, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(Thread-2, started daemon 140428006546224)>
    │    │        │    └ ()
    │    │        └ <Thread(Thread-2, started daemon 140428006546224)>
    │    └ <bound method IntervalRunner._run of <slack_sdk.socket_mode.interval_runner.IntervalRunner object at 0x7fb7f1a039d0>><Thread(Thread-2, started daemon 140428006546224)>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/interval_runner.py", line 19, in _run
    self.target()
    │    └ <bound method SocketModeClient._monitor_current_session of <slack_sdk.socket_mode.builtin.client.SocketModeClient object at 0...
    └ <slack_sdk.socket_mode.interval_runner.IntervalRunner object at 0x7fb7f1a039d0>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/client.py", line 300, in _monitor_current_session
    self.connect_to_new_endpoint()
    │    └ <function BaseSocketModeClient.connect_to_new_endpoint at 0x7fb7f2e9d8b0><slack_sdk.socket_mode.builtin.client.SocketModeClient object at 0x7fb7f1aaeb50>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/client.py", line 78, in connect_to_new_endpoint
    self.connect()
    │    └ <function SocketModeClient.connect at 0x7fb7f2eb0430><slack_sdk.socket_mode.builtin.client.SocketModeClient object at 0x7fb7f1aaeb50>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/client.py", line 181, in connect
    current_session.connect()
    │               └ <function Connection.connect at 0x7fb7f2ea9e50><slack_sdk.socket_mode.builtin.connection.Connection object at 0x7fb7f12e6910>
> File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/connection.py", line 139, in connect
    status, headers, text = _parse_handshake_response(sock)
                            │                         └ <ssl.SSLSocket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 52092), raddr=(...
                            └ <function _parse_handshake_response at 0x7fb7f2ea9820>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 136, in _parse_handshake_response
    line = _read_http_response_line(sock)
           │                        └ <ssl.SSLSocket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 52092), raddr=(...
           └ <function _read_http_response_line at 0x7fb7f2ea9790>
  File "/usr/local/lib/python3.9/site-packages/slack_sdk/socket_mode/builtin/internals.py", line 115, in _read_http_response_line
    c: str = sock.recv(1).decode("utf-8")
             │    └ <function SSLSocket.recv at 0x7fb7f4c61b80><ssl.SSLSocket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 52092), raddr=(...
  File "/usr/local/lib/python3.9/ssl.py", line 1226, in recv
    return self.read(buflen)
           │    │    └ 1
           │    └ <function SSLSocket.read at 0x7fb7f4c61430><ssl.SSLSocket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 52092), raddr=(...
  File "/usr/local/lib/python3.9/ssl.py", line 1101, in read
    return self._sslobj.read(len)
           │    │       │    └ 1
           │    │       └ <method 'read' of '_ssl._SSLSocket' objects>
           │    └ <_ssl._SSLSocket object at 0x7fb7f15b9570><ssl.SSLSocket fd=9, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('172.18.0.3', 52092), raddr=(...

socket.timeout: The read operation timed out

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

  • slack_bolt.App and/or its core components
  • slack_bolt.async_app.AsyncApp and/or its core components
  • Adapters in slack_bolt.adapter
  • Others

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.

@mwbrooks mwbrooks added area:adapter question M-T: User needs support to use the project labels Feb 17, 2022
@mwbrooks
Copy link
Member

Hey @tom0010 👋🏻 Thanks for reaching out and cool to hear that you're running 5 socket connections!

We've found the Socket Mode connection to timeout/reconnection periodically, which is what you've linked in slackapi/bolt-python#529

I just want to clarify that your question is how to silence the traceback output when a socket times-out? Ideally, being able to handle the exception yourself?

@tom0010
Copy link
Author

tom0010 commented Feb 17, 2022

Hi @mwbrooks thats exactly it, the traceback is informative but actually I don’t need to see the whole trace when a socket connection times out, so I’d like to catch the exception with a log message, saying something like it timed out and a new socket will be started or something.

@mwbrooks
Copy link
Member

Great, thanks @tom0010!

I had a chat with @seratch. He pointed out that python-slack-sdk has a trace_enabled option (default: False). So we can update the SDK to only print the socket mode tracebacks when the option is enabled.

I'm going to transfer this issue to slackapi/python-slack-sdk and switch it to a feature enhancement!

@mwbrooks mwbrooks transferred this issue from slackapi/bolt-python Feb 17, 2022
@mwbrooks mwbrooks added enhancement M-T: A feature request for new functionality socket-mode and removed question M-T: User needs support to use the project area:adapter labels Feb 17, 2022
@mwbrooks mwbrooks added this to the 3.16.0 milestone Feb 17, 2022
@seratch seratch changed the title Add exception handling for socket mode - socket.timeout: the read operation timed out How to handle ok: false patterns in AsyncWebClient Feb 17, 2022
@seratch seratch changed the title How to handle ok: false patterns in AsyncWebClient Add exception handling for socket mode - socket.timeout: the read operation timed out Feb 17, 2022
seratch added a commit to seratch/python-slack-sdk that referenced this issue Feb 18, 2022
@seratch
Copy link
Member

seratch commented Feb 18, 2022

Hi @tom0010, I just submitted a pull request resolving this issue #1182

@mwbrooks
Copy link
Member

Hi @tom0010, I just submitted a pull request resolving this issue #1182

So quick @seratch! ✅

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
Projects
None yet
3 participants