Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pg/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,11 @@ class AwsPGPooledConnection extends BaseAwsPgClient {
throw new UndefinedClientError();
}
this.pluginService.removeErrorListener(this.targetClient);
return await this.targetClient.client.release();
// After failover, the new target client may not have a release() method
// (e.g., a direct connection instead of a pooled connection).
if (typeof this.targetClient.client?.release === "function") {
return await this.targetClient.client.release();
}
},
null
);
Expand Down
6 changes: 6 additions & 0 deletions pg/lib/icp/pg_internal_pool_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export class AwsPgInternalPoolClient implements AwsInternalPoolClient {

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

async end(): Promise<any> {
Expand Down