Repository navigation
Description
PostgresDatabaseAnalyzer.getTableDefinitions() starts three metadata queries for every discovered table in one Future.wait. The number of pending requests therefore grows with the schema, rather than the connection pool. For example, the linked synthetic 480-table test observes all 480 tables starting immediately, or 1,440 metadata requests.
Each table then awaits the columns, foreign keys and indexes separately. If columns fails before the others, foreign-key/index failures can become unhandled asynchronous errors. That can turn a handled database failure into a zoned startup/test error.
Version and source
Confirmed by source inspection in released serverpod_database 4.0.0 and 4.1.2 and upstream main d0646fbea25837ab7586073955bebfb5be879ecb (23 November 2026). The standalone reproduction was executed against that main revision on macOS arm64, Dart 3.12.2.
Reproduction
Copy postgres_analyzer_concurrency_test.dart from draft PR #6046 into packages/serverpod_database/test/, resolve the upstream workspace as documented in CONTRIBUTING.md, and run:
cd packages/serverpod_database
dart test test/postgres_analyzer_concurrency_test.dart --reporter expandedNo PostgreSQL server or application schema is needed. The tests call the real getTableDefinitions() implementation; controlled catalog results and metadata futures expose the scheduling and error behavior.
Unmodified main: six pass, three fail. The failures demonstrate (1) all 480 tables started while initial queries are blocked, (2) four unhandled sibling errors across two tables, and (3) returning a failure before already-started metadata calls settle.
The reproduction demonstrates scheduling and error ownership. It does not simulate PostgreSQL itself or independently reproduce a pool-acquire timeout.
Proposed fix
Use three table workers, with all three metadata futures observed together per table. This caps metadata work at nine concurrent requests, preserves catalog order, waits for already-started work, and stops assigning tables after a worker observes failure. The work bound then does not grow with the number of tables.
The proposed patch has no public API or dependency changes. Nine regression cases and 27 existing normalization/comparison cases pass with the patch; focused analysis reports no issues. Full workspace CI, real-PostgreSQL integration and performance benchmarking remain to be run upstream.
Possibly related: #4645. That report was closed as stale following discussion about transaction-pooler locks. This reproduction isolates an analyzer scheduling/error-handling defect; it does not establish the cause of every failure in that report.
Would maintainers prefer this conservative concurrency bound or another bounded strategy? Prepared with AI assistance; validation results are supplied for review.
Proposed implementation and regression tests: #6046 (draft; contributor review and upstream CI pending).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog 🗂️
Activity