File tree Expand file tree Collapse file tree 1 file changed +16
-4
lines changed
slack_sdk/socket_mode/builtin Expand file tree Collapse file tree 1 file changed +16
-4
lines changed Original file line number Diff line number Diff line change 1+ import errno
12import hashlib
23import itertools
34import os
@@ -203,10 +204,21 @@ def _receive_messages(
203204 def receive (specific_buffer_size : Optional [int ] = None ):
204205 size = specific_buffer_size if specific_buffer_size is not None else receive_buffer_size
205206 with sock_receive_lock :
206- received_bytes = sock .recv (size )
207- if all_message_trace_enabled :
208- logger .debug (f"Received bytes: { received_bytes } " )
209- return received_bytes
207+ try :
208+ received_bytes = sock .recv (size )
209+ if all_message_trace_enabled :
210+ if len (received_bytes ) > 0 :
211+ logger .debug (f"Received bytes: { received_bytes } " )
212+ return received_bytes
213+ except OSError as e :
214+ # For Linux/macOS, errno.EBADF is the expected error for bad connections.
215+ # The errno.ENOTSOCK can be sent when running on Windows OS.
216+ if e .errno in (errno .EBADF , errno .ENOTSOCK ):
217+ # Note that bad connections can be detected by monitoring threads
218+ # the Socket Mode client automatically reconnects to a new endpoint later.
219+ logger .debug ("The connection seems to be already closed." )
220+ return bytes ()
221+ raise e
210222
211223 return _fetch_messages (
212224 messages = [],
You can’t perform that action at this time.
0 commit comments