codeflash-internal/django
Codeflash Bot 8734f5a0f8 Fix PostgreSQL connection pool exhaustion in log_features
Bug: PostgreSQL connection pool timeout (30 seconds)
Root cause: log_features uses @sync_to_async(thread_sensitive=False), causing
each call to grab a separate database connection from the pool. When multiple
optimization requests run concurrently, the pool (max_size=10) exhausts.

Error seen: psycopg_pool.PoolTimeout: couldn't get a connection after 30.00 sec

Fix: Change thread_sensitive=False to thread_sensitive=True. This ensures Django
properly reuses connections across async/sync boundaries instead of allocating
a new connection for each call.

Affected trace IDs from logs:
- a0d8dab6-6524-47dc-9c82-5fa92e6390fb
- 62f5c35b-7161-4ab0-958a-4865231f5188
- ddc0e882-f914-49e4-a2ac-2d5f19a17507
- eaeb0cbe-6474-4808-9092-42f837dd52cf

Testing:
- Added test_log_features_concurrency.py to verify thread_sensitive=True
- Verified reproduction script now passes without pool exhaustion
- All existing tests pass

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-03-31 23:49:51 +00:00
..
aiservice Fix PostgreSQL connection pool exhaustion in log_features 2026-03-31 23:49:51 +00:00
.dockerignore local setup (#1898) 2025-11-17 12:35:09 -08:00