fix: add httpx.Client cleanup in storage and command parser#12
fix: add httpx.Client cleanup in storage and command parser#12devonjones merged 4 commits intomainfrom
Conversation
Add explicit close() methods to PostgresStorage and CommandParser to properly clean up HTTP clients during graceful shutdown. Changes: - Add PostgresStorage.close() to close httpx.Client - Add CommandParser.close() to close httpx.Client - Call both close methods in ReflexBot.close() during shutdown - Use asyncio.to_thread for non-async close calls - Add error handling to continue shutdown on cleanup failures Benefits: - Prevents resource leaks from unclosed connections - Proper cleanup for orchestrated environments (K8s) - Follows best practices for HTTP client lifecycle Resolves cortex-fei3 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary of ChangesHello @devonjones, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the application's stability and resource management by implementing explicit cleanup mechanisms for HTTP clients used within the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly identifies and fixes resource leaks by adding close() methods for httpx.Client instances. My review focuses on a few key areas for improvement. I've identified another resource leak with the PostgreSQL connection not being closed, and I've provided a suggestion to fix it. I also recommend refactoring the new cleanup logic to avoid code duplication. Most importantly, I've raised concerns about using synchronous libraries like httpx.Client in an asynchronous application, which can lead to performance bottlenecks, and strongly recommend migrating to httpx.AsyncClient for non-blocking I/O.
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively addresses potential resource leaks by adding cleanup logic for httpx.Client instances in PostgresStorage and CommandParser. The introduction of the _close_component helper method in ReflexBot is a good design choice, providing a centralized, safe way to close components during shutdown, correctly using asyncio.to_thread for synchronous operations and including robust error handling. My review includes a couple of suggestions to enhance type safety and improve logging consistency, which will contribute to the long-term maintainability of the code. Overall, these changes are a valuable improvement for the application's stability and robustness.
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces important resource management improvements by ensuring httpx.Client instances are properly closed during shutdown. The addition of close() methods to PostgresStorage and CommandParser is a good practice. The new _close_component helper method in ReflexBot is well-designed, correctly using asyncio.to_thread for synchronous cleanup operations and including robust error handling to prevent shutdown failures. Overall, these changes enhance the application's stability and prevent resource leaks. I have one minor suggestion regarding type hinting to improve maintainability.
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Adds explicit close() methods to properly clean up HTTP clients during graceful shutdown.
Changes:
PostgresStorage.close()to close httpx.ClientCommandParser.close()to close httpx.ClientReflexBot.close()during shutdownasyncio.to_threadfor non-async close callsBenefits:
Testing:
Resolves cortex-fei3