Skip to content

Conversation

@gioboa
Copy link
Collaborator

@gioboa gioboa commented Nov 28, 2025

Description of change

Currently, the MysqlConnectionOptions poolSize option specifies the connection limit for all replica connections.

In this case, you cannot specify a connection limit for each master or slave.

For example, if you only want to create one master connection and up to 10 slave connections, Typeorm has no solution.

I added the MysqlConnectionCredentialsOptions poolSize option, allowing you to specify a poolSize for each replica.

Verification Method

If the master's poolSize is 1 and the `slaves[0] poolSize is 2,
then the master connection should be open at most 1, and the slaves[0] connection should be open at most 2.

Pull-Request Checklist

  • [o ] Code is up-to-date with the master branch
  • This pull request links relevant issues as Fixes #00000
  • There are new or updated unit tests validating the change
  • Documentation has been updated to reflect this change

Related Issues

#8799

Summary by CodeRabbit

  • New Features
    • Added an optional pool size setting for MySQL connection credentials to control max clients per pool.
    • Credentials-level pool size now overrides the global pool setting when provided (including zero).
    • Backward compatible when pool size is unspecified.

@qodo-free-for-open-source-projects

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

8799 - PR Code Verified

Compliant requirements:

  • Add a new connection variable to separate the connectionLimit for master and slave connections
  • Allow different connection limits for master and slave to support write-intensive applications
  • Enable specifying different poolSize values for master and slave connections independently
  • Support MySQL and Aurora MySQL database drivers

Requires further human verification:

  • Verify that the solution works correctly with RDS load balancers for read replicas
  • Test that the master connection limit can be set to 1 while slave connections can be set to 10 (as per the example in PR description)
  • Confirm backward compatibility when poolSize is not specified at the credential level
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Tests

The PR adds a new feature allowing per-connection poolSize configuration, but no unit tests are included to verify the behavior. Tests should validate that credential-level poolSize overrides global poolSize, that fallback to global poolSize works when not specified, and that zero values are handled correctly.

    connectionLimit: credentials.poolSize ?? options.poolSize,
},
Documentation Clarity

The comment 'for each connection' on line 49 is unclear and grammatically incomplete. It should be rephrased to clearly explain that this poolSize setting applies to the specific connection credential and overrides the global poolSize option when provided.

/**
 * Maximum number of clients the pool should contain.
 * for each connection
 */
readonly poolSize?: number

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 28, 2025

typeorm-sql-js-example

npm i https://pkg.pr.new/typeorm/typeorm@11810

commit: 80236a4

@qodo-free-for-open-source-projects
Copy link

qodo-free-for-open-source-projects bot commented Nov 28, 2025

PR Code Suggestions ✨

Latest suggestions up to 80236a4

CategorySuggestion                                                                                                                                    Impact
Possible issue
Validate poolSize is positive integer

Validate that the poolSize option is a positive integer before assigning it to
connectionLimit to prevent potential connection pool issues.

src/driver/mysql/MysqlDriver.ts [1290]

-connectionLimit: credentials.poolSize ?? options.poolSize,
+connectionLimit: (credentials.poolSize && credentials.poolSize > 0) 
+    ? credentials.poolSize 
+    : options.poolSize,
  • Apply / Chat
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that an invalid poolSize (e.g., zero or negative) could cause connection pool issues, and proposes adding a check to ensure it is a positive number, which improves the robustness of the configuration.

Low
  • More

Previous suggestions

Suggestions up to commit 995a4a2
CategorySuggestion                                                                                                                                    Impact
Possible issue
Validate poolSize before use

Validate that the poolSize from credentials is a positive number before
assigning it to connectionLimit. If the validation fails, fall back to the
poolSize from options.

src/driver/mysql/MysqlDriver.ts [1290]

-connectionLimit: credentials.poolSize ?? options.poolSize,
+connectionLimit: (credentials.poolSize && credentials.poolSize > 0) ? credentials.poolSize : options.poolSize,
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that poolSize should be a positive number and adds validation to prevent potential connection pool issues from invalid configuration, improving the code's robustness.

Low
Suggestions up to commit 0155f7a
CategorySuggestion                                                                                                                                    Impact
Possible issue
Validate poolSize before use

Validate that credentials.poolSize is a positive number before using it for the
connectionLimit, falling back to options.poolSize if the validation fails.

src/driver/mysql/MysqlDriver.ts [1290]

-connectionLimit: credentials.poolSize ?? options.poolSize,
+connectionLimit: (credentials.poolSize && credentials.poolSize > 0) ? credentials.poolSize : options.poolSize,
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly identifies that a non-positive poolSize could cause issues and proposes a valid check, improving the robustness of the configuration handling.

Low
Suggestions up to commit e11b7fa
CategorySuggestion                                                                                                                                    Impact
Possible issue
Use logical OR to prevent invalid pool size

Replace the nullish coalescing operator (??) with the logical OR operator (||)
to handle the poolSize configuration. This prevents a poolSize of 0 from being
passed to the driver, which would cause issues, and instead falls back to the
next option or the driver's default.

src/driver/mysql/MysqlDriver.ts [1290]

-connectionLimit: credentials.poolSize ?? options.poolSize,
+connectionLimit: credentials.poolSize || options.poolSize,
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies that a poolSize of 0 is problematic for a connection pool and proposes using || instead of ?? to prevent this invalid configuration from being passed to the driver, thus improving the robustness of the connection logic.

Medium

Copy link
Collaborator

@pkuczynski pkuczynski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add a bit of documentation and unit test for it?

Copy link
Collaborator Author

@gioboa gioboa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll add the documentation.
idk if we can test replicas, I will check

@gioboa
Copy link
Collaborator Author

gioboa commented Nov 29, 2025

Shall we add a bit of documentation and unit test for it?

The documentation for all the MysqlConnectionCredentialsOptions properties is missing. I think we can create another PR to achieve the documentation for these props.

@coveralls
Copy link

coveralls commented Nov 29, 2025

Coverage Status

coverage: 80.766% (-0.004%) from 80.77%
when pulling 80236a4 on gioboa:feat/pool-size
into 835647a on typeorm:master.

@gioboa gioboa merged commit 67f793f into typeorm:master Nov 30, 2025
64 checks passed
@gioboa gioboa deleted the feat/pool-size branch November 30, 2025 11:31
ThbltLmr pushed a commit to ThbltLmr/typeorm that referenced this pull request Dec 2, 2025
Co-authored-by: 아이작_조서환 <wtae1216@sooplive.com>
mgohin pushed a commit to mgohin/typeorm that referenced this pull request Jan 15, 2026
Co-authored-by: 아이작_조서환 <wtae1216@sooplive.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants