Files
twenty/packages/twenty-server
Sonarly Claude Code 01c8a64f5b fix: add connection pool resilience for parallel nested relation queries
https://sonarly.com/issue/19549?type=bug

A `FindOneCompany` GraphQL query fails with "Connection terminated unexpectedly" when the server fires many parallel relation queries that exhaust or destabilize the PostgreSQL connection pool under memory pressure.

Fix: Replaced `Promise.all` with a sequential `for...of` loop in `ProcessNestedRelationsV2Helper.processNestedRelations()` to serialize nested relation database queries.

**Problem:** The `FindOneCompany` GraphQL query (and similar record queries) request 10+ relations simultaneously (accountOwner, attachments, favorites, people, noteTargets, opportunities, timelineActivities, etc.). The previous code fired all these as parallel database queries via `Promise.all`, which could exhaust the default PostgreSQL connection pool (10 connections), causing `Connection terminated unexpectedly` errors.

**Fix:** Sequential execution ensures only 1 relation query runs at a time, keeping concurrent DB connections well within pool limits. Individual relation queries are fast (typically 2-50ms), so serialization adds negligible wall-clock time (~100-500ms total for 10 relations) compared to the catastrophic failure it prevents.

**Precedent:** This follows the exact same pattern merged in commit `0a1ac48eea` which serialized cache recomputation in `WorkspaceCacheService.recomputeDataFromProvider()` to prevent the same class of pool exhaustion bug.
2026-03-30 12:08:52 +00:00
..
2026-03-30 10:53:31 +02:00
2025-12-17 08:48:17 +01:00
2025-08-11 14:10:04 +02:00