-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: impl PoolWaitTimeoutError #7
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
PoolWaitTimeoutError
class is well-implemented, extending theError
class 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
poolWaitTimeout
property toRDSClientOptions
enhances configuration flexibility and is backward-compatible.src/client.ts (6)
3-3
: LGTM!The import of
setTimeout
fromnode:timers/promises
is appropriate for implementing the connection timeout functionality.
65-65
: LGTM!The
#poolWaitTimeout
property is well-defined, providing a default value of 500ms, which is a reasonable default for connection timeouts.
86-86
: LGTM!The initialization of
#poolWaitTimeout
in the constructor is correct, ensuring the property is set based on options or defaults.
155-159
: LGTM!The
waitPoolConnection
method is well-implemented, usingsetTimeout
for timeout management and supporting cancellation withAbortSignal
.
161-174
: LGTM!The
getConnectionWithTimeout
method is well-designed, usingPromise.race
to manage connection acquisition and handle timeouts effectively.
178-180
: LGTM!The update to use
getConnectionWithTimeout
ingetConnection
improves error handling and connection management.test/client.test.ts (4)
1499-1504
: LGTM!The
longQuery
function 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
后续得去给 getConnection 加一个 abortSignal 支持,就不需要写下面这种 hack 逻辑。
connPromise 这段逻辑代码其实也奇怪,一拿到 conn 就马上释放。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mysql 还停留在 callback 的写法,这个改动比较难了。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单测修复一下?其他没问题了。
Throw error when get connection wait time great than poolWaitTimeout.
2d7942c
to
8dd743c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 variableid
is correctly initialized.The static variable
id
is initialized to 0 to serve as a unique identifier counter forRDSTransaction
instances. This is a valid approach for tracking instances.
9-13
: Unique identifierid
is effectively implemented.The
id
property is added to theRDSTransaction
class 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#released
is correctly added and initialized.The
#released
property is added to track the release state of the connection. It is initialized tofalse
to indicate that the connection has not been released initially. This is a good practice for managing connection state.
30-31
: Update torelease
method enhances robustness.The assertion in the
release
method ensures that a connection can only be released once by checking the#released
property. 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))
Throw error when get connection wait time great than poolWaitTimeout.
Summary by CodeRabbit
New Features
Bug Fixes
Tests