Conversation
WalkthroughThe recent updates enhance the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant RDSClient
participant ConnectionPool
participant Timer
User->>RDSClient: Request connection
RDSClient->>Timer: Start timeout
RDSClient->>ConnectionPool: Get connection
alt Connection available
ConnectionPool-->>RDSClient: Provide connection
RDSClient-->>User: Return connection
else Timeout occurs
Timer-->>RDSClient: Notify timeout
RDSClient-->>User: Throw PoolWaitTimeoutError
end
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- README.md (1 hunks)
- src/client.ts (5 hunks)
- src/types.ts (1 hunks)
- src/util/PoolWaitTimeout.ts (1 hunks)
- test/client.test.ts (2 hunks)
Files skipped from review due to trivial changes (1)
- README.md
Additional comments not posted (12)
src/util/PoolWaitTimeout.ts (1)
1-5: LGTM!The
PoolWaitTimeoutErrorclass is well-implemented, extending theErrorclass and setting a custom name. This is a good practice for distinguishing specific error types.src/types.ts (1)
11-11: LGTM!The addition of the
poolWaitTimeoutproperty toRDSClientOptionsenhances configuration flexibility and is backward-compatible.src/client.ts (6)
3-3: LGTM!The import of
setTimeoutfromnode:timers/promisesis appropriate for implementing the connection timeout functionality.
65-65: LGTM!The
#poolWaitTimeoutproperty is well-defined, providing a default value of 500ms, which is a reasonable default for connection timeouts.
86-86: LGTM!The initialization of
#poolWaitTimeoutin the constructor is correct, ensuring the property is set based on options or defaults.
155-159: LGTM!The
waitPoolConnectionmethod is well-implemented, usingsetTimeoutfor timeout management and supporting cancellation withAbortSignal.
161-174: LGTM!The
getConnectionWithTimeoutmethod is well-designed, usingPromise.raceto manage connection acquisition and handle timeouts effectively.
178-180: LGTM!The update to use
getConnectionWithTimeoutingetConnectionimproves error handling and connection management.test/client.test.ts (4)
1499-1504: LGTM!The
longQueryfunction is well-structured for simulating long-running queries with a default timeout.
1506-1515: LGTM!The test case correctly verifies that an error is thrown when the pool wait timeout is exceeded.
1517-1544: LGTM!The test case effectively checks that connections are released back to the pool after timeout.
1546-1587: LGTM!The test case accurately validates that the overall execution time is within the expected threshold.
| const timeoutPromise = this.waitPoolConnection(timeoutAbortController.signal); | ||
| const connOrTimeout = await Promise.race([ connPromise, timeoutPromise ]); | ||
| if (typeof connOrTimeout === 'number') { | ||
| connPromise.then(conn => { |
There was a problem hiding this comment.
后续得去给 getConnection 加一个 abortSignal 支持,就不需要写下面这种 hack 逻辑。
connPromise 这段逻辑代码其实也奇怪,一拿到 conn 就马上释放。
There was a problem hiding this comment.
mysql 还停留在 callback 的写法,这个改动比较难了。
Throw error when get connection wait time great than poolWaitTimeout.
2d7942c to
8dd743c
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (7)
- README.md (1 hunks)
- src/client.ts (5 hunks)
- src/connection.ts (3 hunks)
- src/transaction.ts (1 hunks)
- src/types.ts (1 hunks)
- src/util/PoolWaitTimeout.ts (1 hunks)
- test/client.test.ts (6 hunks)
Files skipped from review due to trivial changes (2)
- README.md
- src/util/PoolWaitTimeout.ts
Files skipped from review as they are similar to previous changes (3)
- src/client.ts
- src/types.ts
- test/client.test.ts
Additional comments not posted (4)
src/transaction.ts (2)
4-4: Static variableidis correctly initialized.The static variable
idis initialized to 0 to serve as a unique identifier counter forRDSTransactioninstances. This is a valid approach for tracking instances.
9-13: Unique identifieridis effectively implemented.The
idproperty is added to theRDSTransactionclass and initialized withid++to ensure each instance has a unique identifier. This implementation is straightforward and effective for tracking instances.src/connection.ts (2)
10-14: Private property#releasedis correctly added and initialized.The
#releasedproperty is added to track the release state of the connection. It is initialized tofalseto indicate that the connection has not been released initially. This is a good practice for managing connection state.
30-31: Update toreleasemethod enhances robustness.The assertion in the
releasemethod ensures that a connection can only be released once by checking the#releasedproperty. This prevents errors from multiple releases and improves connection management.
[skip ci] ## [1.2.0](v1.1.0...v1.2.0) (2024-08-12) ### Features * impl PoolWaitTimeoutError ([#7](#7)) ([f42012d](f42012d))
[skip ci] ## 1.0.0 (2024-01-30) ### ⚠ BREAKING CHANGES * In `Promise.all` case, Parallel beginTransactionScope will create isolated transactions. * drop Node.js < 16 support ### Features * add *beginTransactionScope(scope) ([0013a63](node-modules/rds@0013a63)) * add count(table, where) ([6286c46](node-modules/rds@6286c46)) * add get(), list(), insert(), update() ([9cae1cb](node-modules/rds@9cae1cb)) * add options.needFields, default is true ([18e0dea](node-modules/rds@18e0dea)) * add queryOne api ([#9](node-modules/rds#9)) ([19fc1bb](node-modules/rds@19fc1bb)) * add Transaction ([cfdcf26](node-modules/rds@cfdcf26)) * add unlock/lock tables ([#97](https://github.com/node-modules/myrds/issues/97)) ([4dc3452](node-modules/rds@4dc3452)) * add unlock/lock tables ([#97](https://github.com/node-modules/myrds/issues/97)) ([0a61be6](node-modules/rds@0a61be6)) * dynamic retrieval of database connection configuration ([#110](https://github.com/node-modules/myrds/issues/110)) ([f437efb](node-modules/rds@f437efb)) * export connection and query diagnostics_channel ([#111](https://github.com/node-modules/myrds/issues/111)) ([64aa75d](node-modules/rds@64aa75d)) * export sqlstring method ([#79](https://github.com/node-modules/myrds/issues/79)) ([2e99ab8](node-modules/rds@2e99ab8)) * impl with typescript ([#103](https://github.com/node-modules/myrds/issues/103)) ([1cf7814](node-modules/rds@1cf7814)) * promiseify ([#20](https://github.com/node-modules/myrds/issues/20)) ([e4aed30](node-modules/rds@e4aed30)) * stats 增加使用中的连接数 ([#115](https://github.com/node-modules/myrds/issues/115)) ([2b152a1](node-modules/rds@2b152a1)) * support custom query lifecricle ([#104](https://github.com/node-modules/myrds/issues/104)) ([5941c69](node-modules/rds@5941c69)) * support doomed transaction scope on test cases ([#58](https://github.com/node-modules/myrds/issues/58)) ([b227bc1](node-modules/rds@b227bc1)) * support end() ([b3eab93](node-modules/rds@b3eab93)) * support insert multi rows ([abb4804](node-modules/rds@abb4804)) * support mysql2 ([#1](node-modules/rds#1)) ([eb9f391](node-modules/rds@eb9f391)) * support query(sql, object) ([#12](node-modules/rds#12)) ([a55e82f](node-modules/rds@a55e82f)) * support transaction on one request ctx ([#7](node-modules/rds#7)) ([3bd4e44](node-modules/rds@3bd4e44)) * update multiple rows ([#55](https://github.com/node-modules/myrds/issues/55)) ([859d818](node-modules/rds@859d818)) * use AsyncLocalStorage to refactor transaction, to make it more safe ([#108](https://github.com/node-modules/myrds/issues/108)) ([ae327fa](node-modules/rds@ae327fa)) * where condition support NULL value ([#60](https://github.com/node-modules/myrds/issues/60)) ([0d4d4ab](node-modules/rds@0d4d4ab)) * wrap generator function to promise ([#19](https://github.com/node-modules/myrds/issues/19)) ([fe1b4a3](node-modules/rds@fe1b4a3)) ### Bug Fixes * `where` with empty object ([#15](node-modules/rds#15)) ([db0b90e](node-modules/rds@db0b90e)) * add default value now() of `gmt_modified` and `gmt_create` ([#56](https://github.com/node-modules/myrds/issues/56)) ([db6d596](node-modules/rds@db6d596)) * don't export protected methods ([#106](https://github.com/node-modules/myrds/issues/106)) ([b2757df](node-modules/rds@b2757df)) * don't redefined sqlstring.escape ([#39](https://github.com/node-modules/myrds/issues/39)) ([5ca4489](node-modules/rds@5ca4489)) * export pool getter from rds client ([#102](https://github.com/node-modules/myrds/issues/102)) ([4048807](node-modules/rds@4048807)) * handle concurrent transaction ([#85](https://github.com/node-modules/myrds/issues/85)) ([d983478](node-modules/rds@d983478)) * move sql to error stack ([#8](node-modules/rds#8)) ([54349cd](node-modules/rds@54349cd)) * mysql type not found ([#109](https://github.com/node-modules/myrds/issues/109)) ([6a9bc45](node-modules/rds@6a9bc45)) * query parameters are not allowed to be included in where ([#67](https://github.com/node-modules/myrds/issues/67)) ([52147de](node-modules/rds@52147de)) * should export conn property ([#101](https://github.com/node-modules/myrds/issues/101)) ([37afa42](node-modules/rds@37afa42)) * support multi lifecricle hooks ([#105](https://github.com/node-modules/myrds/issues/105)) ([53b0a70](node-modules/rds@53b0a70)) * use master branch ([758877d](node-modules/rds@758877d))
Throw error when get connection wait time great than poolWaitTimeout.
Summary by CodeRabbit
New Features
Bug Fixes
Tests