Skip to content

Commit b802add

Browse files
authored
fix(pg): prevent process crash during Aurora failover (#621)
1 parent 9d4d7b0 commit b802add

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

pg/lib/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,11 @@ class AwsPGPooledConnection extends BaseAwsPgClient {
358358
throw new UndefinedClientError();
359359
}
360360
this.pluginService.removeErrorListener(this.targetClient);
361-
return await this.targetClient.client.release();
361+
// After failover, the new target client may not have a release() method
362+
// (e.g., a direct connection instead of a pooled connection).
363+
if (typeof this.targetClient.client?.release === "function") {
364+
return await this.targetClient.client.release();
365+
}
362366
},
363367
null
364368
);

pg/lib/icp/pg_internal_pool_client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ export class AwsPgInternalPoolClient implements AwsInternalPoolClient {
2525

2626
constructor(props: pkgPg.PoolConfig) {
2727
this.targetPool = new pkgPg.Pool(props);
28+
// Handle idle client errors to prevent process crash during Aurora failover.
29+
// When a failover occurs, idle connections in the pool are terminated by the server,
30+
// which emits 'error' events. Without this handler, Node.js throws an uncaught exception.
31+
this.targetPool.on("error", () => {
32+
// Intentionally swallowed. The failover plugin will handle reconnection.
33+
});
2834
}
2935

3036
async end(): Promise<any> {

0 commit comments

Comments
 (0)