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

websocket_client-based SocketModeClient does not reconnect after a DNS outage #1462

Closed
ktindall-godaddy opened this issue Feb 16, 2024 · 1 comment · Fixed by #1466
Closed
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x
Milestone

Comments

@ktindall-godaddy
Copy link

Reproducible in:

slack_sdk==3.26.2
Python 3.9.18
ProductName:            macOS
ProductVersion:         13.6.4
BuildVersion:           22G513
Darwin Kernel Version 22.6.0: Sun Dec 17 22:13:25 PST 2023; root:xnu-8796.141.3.703.2~2/RELEASE_ARM64_T6020

Steps to reproduce:

  1. Have a SocketModeClient with these settings:
import os
from slack_sdk.socket_mode.websocket_client import SocketModeClient
from slack_sdk.web import WebClient

web_client = WebClient(token=os.environ["SLACK_WEB_TOKEN"])
socket_client = SocketModeClient(
    app_token=os.environ["SLACK_APP_TOKEN"],
    web_client=web_client,
    concurrency=100,
    auto_reconnect_enabled=True,
    trace_enabled=True,
)
socket_client.connect()
  1. While that client is running, disconnect it from the Internet. This forces the active websockets to lose connection and simulates a DNS outage.
  2. Wait until these stacktraces appear in an infinite loop:
2024-02-15 14:32:20,957 INFO:slack_sdk.socket_mode.websocket_client:Starting to receive messages from a new connection
2024-02-15 14:32:20,957 - slack_sdk.socket_mode.websocket_client - INFO - Starting to receive messages from a new connection
2024-02-15 14:32:20,958 ERROR:slack_sdk.socket_mode.websocket_client:Failed to start or stop the current session: socket is already opened
Traceback (most recent call last):
  File "/path/venv/lib/python3.9/site-packages/slack_sdk/socket_mode/websocket_client/__init__.py", line 237, in _run_current_session
    self.current_session.run_forever(
  File "/path/venv/lib/python3.9/site-packages/websocket/_app.py", line 422, in run_forever
    raise WebSocketException("socket is already opened")
websocket._exceptions.WebSocketException: socket is already opened
  1. Reconnect the Internet and observe that the client never reconnects and continues providing the stacktraces above.

Expected result:

I expected the client to reconnect.

Actual result:

The client never reconnects.

Possible fix:

This function could set self.current_session = None in the event of an Exception.

def _run_current_session(self):
if self.current_session is not None:
try:
self.logger.info("Starting to receive messages from a new connection")
self.current_session.run_forever(
ping_interval=self.ping_interval,
http_proxy_host=self.http_proxy_host,
http_proxy_port=self.http_proxy_port,
http_proxy_auth=self.http_proxy_auth,
proxy_type=self.proxy_type,
)
self.logger.info("Stopped receiving messages from a connection")
except Exception as e:
self.logger.exception(f"Failed to start or stop the current session: {e}")

@ktindall-godaddy ktindall-godaddy changed the title (Set a clear title describing the issue) SocketModeClient does not reconnect after a DNS outage Feb 16, 2024
@seratch seratch added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x socket-mode and removed untriaged labels Feb 22, 2024
@seratch seratch added this to the 3.27.1 milestone Feb 22, 2024
@seratch seratch changed the title SocketModeClient does not reconnect after a DNS outage websocket_client -based SocketModeClient does not reconnect after a DNS outage Feb 22, 2024
@seratch seratch changed the title websocket_client -based SocketModeClient does not reconnect after a DNS outage websocket_client-based SocketModeClient does not reconnect after a DNS outage Feb 22, 2024
@seratch
Copy link
Member

seratch commented Feb 22, 2024

Thanks for reporting this issue. I'll look into this issue early next week.

seratch added a commit to seratch/python-slack-sdk that referenced this issue Feb 28, 2024
seratch added a commit that referenced this issue Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented socket-mode Version: 3x
Projects
None yet
2 participants