Skip to content

fix: remove asyncio.run() from __del__ to prevent production crashes#156

Open
bleedblack1 wants to merge 1 commit intoreactome:mainfrom
bleedblack1:fix/asyncio-run-crash
Open

fix: remove asyncio.run() from __del__ to prevent production crashes#156
bleedblack1 wants to merge 1 commit intoreactome:mainfrom
bleedblack1:fix/asyncio-run-crash

Conversation

@bleedblack1
Copy link
Copy Markdown

Fixes #154

Problem

The AgentGraph.__del__ method crashes in production:

def __del__(self) -> None:
    if self.pool:
        asyncio.run(self.close_pool())  #  RuntimeError!

Why it crashes: asyncio.run() cannot be called when an event loop is already running, which is always the case in Chainlit/uvicorn/FastAPI.

Secondary issue: LANGGRAPH_DB_URI is constructed at module import with potentially None values, creating malformed URIs.

Solution

Change Purpose
Remove del Eliminates the crash
Add aenter/aexit Proper async context manager pattern
Add close() method Explicit, idempotent cleanup
Add _build_langgraph_db_uri() Lazy URI construction with validation
Add is_initialized/is_closed State inspection properties
Add create_agent_graph() Convenience factory function

Related Issues

  • Fixes the asyncio.run() crash bug
  • Addresses malformed URI construction
  • Improves resource management patterns

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: asyncio.run() in __del__ causes RuntimeError crash in production

1 participant