Fix: ActiveRecord::ConnectionTimeoutError (MAYBE-RAILS-CZ) #1685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The ActiveRecord::ConnectionTimeoutError occurs when the application attempts to obtain a database connection but all connections in the pool are in use. The error indicates that the current pool size is insufficient to handle the concurrent database connections needed by both Puma (web server) and GoodJob (background job processor).
The original configuration in database.yml had a fixed pool size of 11, calculated based on assumptions about thread usage (3 for Puma, 8 for GoodJob). However, this static configuration doesn't account for variations in thread counts that might be set through environment variables.
The fix involves:
In config/database.yml, we're updating the pool configuration to dynamically calculate the required connections based on:
This ensures that the connection pool always has enough connections to handle all possible concurrent database operations, preventing connection timeout errors while not over-allocating database connections.
Tip
You can make revisions or ask questions of Revise.dev by using
/revise
in any comment or review!/revise Add a comment above the method to explain why we're making this change.
/revise Why did you choose to make this change specifically?
Important
If something doesn't look right, click to retry this interaction.