Skip to content

Commit ed0804f

Browse files
committed
Fix connection pool exhaustion in process_review_request
Release the database connection before the long-running AI processing. This prevents the connection from being held idle for minutes during process_review(), which was exhausting the connection pool.
1 parent fb29387 commit ed0804f

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

services/reviewhelper-api/app/routers/internal.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,19 @@ async def _set_retry_pending(db: AsyncSession):
118118
)
119119
comments = await review_request.awaitable_attrs.comments
120120
else:
121+
# Release the connection before the long-running AI processing to avoid
122+
# exhausting the connection pool (see #5867). A new pool connection will
123+
# be acquired on the next database operation.
124+
await db.close()
125+
121126
try:
122-
comments, patch_summary, details = await process_review(review_request)
127+
try:
128+
comments, patch_summary, details = await process_review(review_request)
129+
finally:
130+
# Re-associate since the identity map was cleared when we closed
131+
# the connection.
132+
db.add(review_request)
133+
123134
except ReviewProcessingError as e:
124135
review_request.error = str(e)
125136
review_request.status = ReviewStatus.FAILED

0 commit comments

Comments
 (0)