perf: 稳定性和性能优化#7
Conversation
## Thread Safety - Add RLock to session dictionary for thread-safe access - Prevent race conditions in concurrent session operations ## WebSocket Improvements - Add 60-second message timeout to prevent zombie connections - Graceful connection close on timeout ## Security - Add sensitive data masking utility (utils/security.py) - Mask API keys and tokens in logs - Add Config.get_service_config_masked() for safe logging ## HTTP Client Management - Add shared HTTP client manager (utils/http_client.py) - Connection pooling with configurable limits - HTTP/2 support enabled - Thread-safe client acquisition with asyncio.Lock ## Code Quality - Remove redundant HTTP client management from TTS services - Fix ruff lint issues 🤖 Generated with [CodeBuddy Code] Co-Authored-By: CodeBuddy Code
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| cls._client = httpx.AsyncClient( | ||
| timeout=timeout_config, | ||
| limits=limits, | ||
| http2=True, # Enable HTTP/2 for better performance |
There was a problem hiding this comment.
Enabling HTTP/2 without declaring required dependency
HTTPClientManager now constructs the shared client with http2=True, but the dependency manifests still declare only httpx>=0.25.2 (no httpx[http2] or h2). On an environment installed from those manifests, creating this client will raise an ImportError for the missing HTTP/2 extras and all TTS HTTP requests will fail at runtime. Either drop HTTP/2 here or add the appropriate extras dependency.
Useful? React with 👍 / 👎.
- Fix frontend/backend command protocol mismatch (command -> type) - Add TextInputCommand model for text input support - Implement text input handler in WebSocket handler - Add text input event binding in frontend app.js - Add HTTP/2 dependency (httpx[http2]) for better performance - Fix user message display (use final_transcript type) 🤖 Generated with [CodeBuddy Code] Co-Authored-By: CodeBuddy Code
Summary
本 PR 包含多项稳定性和性能优化:
线程安全
RLock锁,防止并发竞态条件WebSocket 改进
安全性
utils/security.pyConfig.get_service_config_masked()方法用于安全日志HTTP 客户端管理
utils/http_client.pyasyncio.Lock保证线程安全代码质量
Changes
session.py_sessions_lock线程安全锁websocket/handler.pyutils/security.pyutils/http_client.pyconfig.pyget_service_config_masked()services/tts/*.pyapp.pyTest plan
🤖 Generated with [CodeBuddy Code]