Hey everyone, I’m having a weird issue with TypeORM and Aurora MySQL. We’re using autoscaling for our read replicas, but TypeORM doesn’t seem to pick up new ones when they’re added.
Our setup:
- TypeORM 0.3.20
- NestJS TypeORM 10.0.2
- Node.js v22.13
- Aurora MySQL 8.0 (autoscaling read replicas)
We’ve got separate endpoints for read and write operations. The problem is, when Aurora adds a new read replica, TypeORM keeps sending all read traffic to the original instance. It’s like it’s not re-checking the endpoint or updating its connection pool.
Here’s a simplified version of our TypeORM config:
TypeOrmModule.forRoot({
type: 'mysql',
replication: {
master: { /* master config */ },
slaves: [{ /* read replica config */ }],
},
// other settings
});
What I’ve noticed:
- TypeORM only sets up its replication pool when the app starts
- It doesn’t seem to check the DNS of the read endpoint again
- New replicas aren’t used until we restart the app
Is there a way to make TypeORM:
- Refresh its connection pool while running?
- Re-check the read endpoint DNS without a restart?
- Handle it smoothly if a replica disappears?
I’m pretty sure our AWS setup is correct. Also, I found out Node.js might cache DNS lookups for up to an hour by default. Could this be part of the problem?
Any ideas on how to fix this? Thanks!