@@ -26,8 +26,7 @@ <h1 class="title">Module <code>slack_sdk.socket_mode.builtin.internals</code></h
2626< summary >
2727< span > Expand source code</ span >
2828</ summary >
29- < pre > < code class ="python "> import errno
30- import hashlib
29+ < pre > < code class ="python "> import hashlib
3130import itertools
3231import os
3332import random
@@ -52,6 +51,8 @@ <h1 class="title">Module <code>slack_sdk.socket_mode.builtin.internals</code></h
5251 line = []
5352 while True:
5453 c = sock.recv(1)
54+ if not c:
55+ raise ConnectionError("Connection is closed")
5556 line.append(c)
5657 if c == b"\n":
5758 break
@@ -142,7 +143,10 @@ <h1 class="title">Module <code>slack_sdk.socket_mode.builtin.internals</code></h
142143def _read_http_response_line(sock: ssl.SSLSocket) -> str:
143144 cs = []
144145 while True:
145- c: str = sock.recv(1).decode("utf-8")
146+ b: bytes = sock.recv(1)
147+ if not b:
148+ raise ConnectionError("Connection is closed")
149+ c: str = b.decode("utf-8")
146150 if c == "\r":
147151 break
148152 if c != "\n":
@@ -227,19 +231,12 @@ <h1 class="title">Module <code>slack_sdk.socket_mode.builtin.internals</code></h
227231 def receive(specific_buffer_size: Optional[int] = None):
228232 size = specific_buffer_size if specific_buffer_size is not None else receive_buffer_size
229233 with sock_receive_lock:
230- try:
231- received_bytes = sock.recv(size)
232- if all_message_trace_enabled:
233- if len(received_bytes) > 0:
234- logger.debug(f"Received bytes: {received_bytes}")
235- return received_bytes
236- except OSError as e:
237- # For Linux/macOS, errno.EBADF is the expected error for bad connections.
238- # The errno.ENOTSOCK can be sent when running on Windows OS.
239- if e.errno in (errno.EBADF, errno.ENOTSOCK):
240- logger.debug("The connection seems to be already closed.")
241- return bytes()
242- raise e
234+ received_bytes = sock.recv(size)
235+ if not received_bytes:
236+ raise ConnectionError("Connection is closed")
237+ if all_message_trace_enabled:
238+ logger.debug(f"Received bytes: {received_bytes}")
239+ return received_bytes
243240
244241 return _fetch_messages(
245242 messages=[],
0 commit comments