Skip to content

Commit 314b425

Browse files
authored
fix: add catch for get conn exception (#13)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Enhanced connection timeout handling with diagnostic logging. Connections are now properly released during timeout scenarios to prevent resource leaks and improve visibility into connection issues. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a1a801d commit 314b425

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
},
1919
"dependencies": {
2020
"mysql2": "^3.9.1",
21-
"sqlstring": "^2.3.3"
21+
"sqlstring": "^2.3.3",
22+
"onelogger": "^1.0.0"
2223
},
2324
"devDependencies": {
2425
"@eggjs/tsconfig": "^1.3.2",

src/client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { promisify } from 'node:util';
33
import { setTimeout } from 'node:timers/promises';
44
import mysql, { Pool } from 'mysql2';
55
import type { PoolOptions } from 'mysql2';
6+
import { getLogger } from 'onelogger';
67
import type { PoolConnectionPromisify, RDSClientOptions, TransactionContext, TransactionScope } from './types';
78
import { Operator } from './operator';
89
import { RDSConnection } from './connection';
@@ -167,6 +168,10 @@ export class RDSClient extends Operator {
167168
if (typeof connOrTimeout === 'number') {
168169
connPromise.then(conn => {
169170
conn.release();
171+
}).catch(e => {
172+
const logger = getLogger();
173+
e.message = 'get conn failed after timeout: ' + e.message;
174+
logger.warn(e);
170175
});
171176
throw new PoolWaitTimeoutError(`get connection timeout after ${connOrTimeout}ms`);
172177
}

0 commit comments

Comments
 (0)