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

fix: 'ClientConnection' object has no attribute 'closed' #1613

Conversation

WilliamBergamin
Copy link
Contributor

@WilliamBergamin WilliamBergamin commented Dec 12, 2024

Summary

This PR aims to resolve #1612

Followed Upgrade to the new asyncio implementation to come up with these changes. Socket mode uses websockets.WebSocketClientProtocol in its implementation, this class was replaced with websockets.asyncio.client.ClientConnection.

These interfaces are very similar but ClientConnection lacks the closed method found in WebSocketClientProtocol. As a workaround proposed to use .close_code is not None to determine if a session is closed or in the process of being closed. Close code is defined in RFC 6455 sec 7.1.5

Testing

  1. Pull this branch
  2. scripts/build_pypi_package.sh
  3. Use path/to/python-slack-sdk/dist/slack_sdk-3.33.5-py2.py3-none-any.whl to pip install the changes in the following project
import sys
import os
import logging
import asyncio
from slack_bolt.async_app import AsyncApp
from slack_bolt.adapter.socket_mode.websockets import AsyncSocketModeHandler

# Initializes your app with your bot token and socket mode handler
app = AsyncApp(token=os.environ.get("SLACK_BOT_TOKEN"))

logging.basicConfig(level=logging.DEBUG)

# Start your app
if __name__ == "__main__":
    if sys.version.startswith("3.6"):
        loop = asyncio.get_event_loop()
        loop.run_until_complete(
            AsyncSocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start_async()
        )
    else:
        asyncio.run(
            AsyncSocketModeHandler(app, os.environ["SLACK_APP_TOKEN"]).start_async()
        )
slack_bolt==1.21.3
path/to/python-slack-sdk/dist/slack_sdk-3.33.5-py2.py3-none-any.whl
aiohttp>=3.7.3,<4
websockets>=9.1,<15

Manually tested with python 3.6 and 3.12

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented Version: 3x socket-mode area:async labels Dec 12, 2024
@WilliamBergamin WilliamBergamin self-assigned this Dec 12, 2024
Copy link

codecov bot commented Dec 12, 2024

Codecov Report

Attention: Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.88%. Comparing base (a7223d9) to head (827a37b).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
slack_sdk/socket_mode/websockets/__init__.py 64.70% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1613      +/-   ##
==========================================
- Coverage   84.93%   84.88%   -0.06%     
==========================================
  Files         113      113              
  Lines       12630    12639       +9     
==========================================
+ Hits        10727    10728       +1     
- Misses       1903     1911       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one minor suggestion. As we discussed internally, let's try re-enabling the interaction tests. If it's still flaky, we can disable it again

slack_sdk/socket_mode/websockets/__init__.py Outdated Show resolved Hide resolved
@seratch seratch added this to the 3.33.6 milestone Dec 12, 2024
@WilliamBergamin WilliamBergamin merged commit 5c57a32 into slackapi:main Dec 13, 2024
12 checks passed
@WilliamBergamin WilliamBergamin deleted the websockets-adapter-fails-missing-close-func branch December 13, 2024 00:03
@zimeg zimeg mentioned this pull request Dec 17, 2024
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:async 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