Skip to content

Commit b34c806

Browse files
authored
Add more revert to #1269 (#1271)
1 parent d558afa commit b34c806

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

slack_sdk/socket_mode/builtin/internals.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import errno
12
import hashlib
23
import itertools
34
import 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=[],

0 commit comments

Comments
 (0)