Fix asyncio event loop conflicts in CdpEvmWalletProvider#968
Open
darrylsj wants to merge 1 commit intocoinbase:mainfrom
Open
Fix asyncio event loop conflicts in CdpEvmWalletProvider#968darrylsj wants to merge 1 commit intocoinbase:mainfrom
darrylsj wants to merge 1 commit intocoinbase:mainfrom
Conversation
- Replace asyncio.run() calls in __init__ with _run_async() helper - Improve _run_async() to detect existing event loops and handle them properly - Run coroutines in separate thread when event loop already exists - Prevents misleading ETIMEDOUT errors when real issue is asyncio conflict - Fixes compatibility with Jupyter notebooks, web frameworks, and agent systems Fixes coinbase#967
🟡 Heimdall Review Status
|
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.
Problem
Fixes #967
The
CdpEvmWalletProvider.__init__method was usingasyncio.run()which fails when an asyncio event loop is already running (common in Jupyter notebooks, web frameworks, and agent orchestration systems). This resulted in misleading "NetworkError(ETIMEDOUT, 'Request timed out')" errors when the real issue was asyncio event loop conflicts.Solution
asyncio.run()calls in__init__with the_run_async()helper method for consistency_run_async()method to properly detect and handle existing event loops:asyncio.get_running_loop()to detect if we're in an existing event loopChanges Made
coinbase_agentkit/wallet_providers/cdp_evm_wallet_provider.pyasyncio.run()with_run_async()_run_async()method with proper event loop handlingBenefits
Testing
The fix has been tested to ensure:
Note on Error Messages
This also addresses the misleading error message issue where asyncio conflicts were being reported as network timeouts. The new implementation allows the actual asyncio errors to propagate properly when they occur, making debugging much easier.
Dependencies
No new dependencies required - uses Python's built-in
concurrent.futuresandthreadingmodules.