fix(gateway): feishu websocket monkey-patch breaks dingtalk and other platforms#20053
Closed
dawell wants to merge 1 commit into
Closed
fix(gateway): feishu websocket monkey-patch breaks dingtalk and other platforms#20053dawell wants to merge 1 commit into
dawell wants to merge 1 commit into
Conversation
The feishu adapter's _connect_with_overrides was declared as 'async def', which returns a coroutine object instead of a context manager. Since Python modules are singletons, the monkey-patch websockets.connect = _connect_with_overrides replaced the global websockets.connect (a normal function returning a context manager) with a coroutine function. Other platforms that import websockets (e.g. dingtalk_stream using 'async with websockets.connect(uri)') would then get: TypeError: 'coroutine' object does not support the asynchronous context manager protocol Fix: change 'async def _connect_with_overrides' to plain 'def', and 'return await original_connect(...)' to 'return original_connect(...)'. This preserves the original connect() return type (context manager) while still injecting ping_interval/ping_timeout overrides. Compatible with websockets 13.x, 15.x, and 16.x.
Collaborator
Collaborator
Contributor
|
This looks implemented on current Evidence:
Thanks for the report and fix; the current main branch has the requested behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
The feishu adapter monkey-patches
websockets.connectglobally:However,
_connect_with_overrideswas declared asasync def, which returns a coroutine object instead of a context manager. Since Python modules are singletons, this replaces the globalwebsockets.connect(a normal function returning a context manager) with a coroutine function.Impact
Any other platform that imports
websocketsand usesasync with websockets.connect(uri)will crash with:Confirmed broken: dingtalk (dingtalk_stream uses
async with websockets.connect(uri)).Potentially affected: any future gateway platform or third-party library that shares the same
websocketsmodule instance.Root Cause
The
awaitunwraps the context manager into a coroutine, breaking theasync withprotocol for all consumers.Fix
async def→def: no longer a coroutine functionreturn await original_connect(...)→return original_connect(...): returns the context manager object directly, preserving the originalwebsockets.connect()interfaceTesting
Verified compatible with websockets 13.x, 15.x, and 16.x. All three gateway platforms (feishu, dingtalk, weixin) connect normally after the fix.