Skip to content

Commit

Permalink
fix: hotStandby - set heartbeats state no matter secondary's state
Browse files Browse the repository at this point in the history
  • Loading branch information
olzzon committed Oct 28, 2024
1 parent f550bd5 commit c2b35be
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/connector/src/MosConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,16 @@ export class MosConnection extends EventEmitter<MosConnectionEvents> implements
// the secondary connection when the primary is connected
// And disable heartbeats on the primary when the primary is disconnected
if (connectionOptions.secondary?.openMediaHotStandby) {
// Initially disable heartbeats on secondary since primary should be attempted first
secondary.disableHeartbeats()

primary.on('connectionChanged', () => {
if (secondary) {
if (primary.connected) {
secondary.disableHeartbeats()
primary.enableHeartbeats()
} else {
secondary.enableHeartbeats()
primary.disableHeartbeats()
}
if (primary.connected) {
secondary?.disableHeartbeats()
primary.enableHeartbeats()
} else {
secondary?.enableHeartbeats()
primary.disableHeartbeats()
}
})
}
Expand Down

0 comments on commit c2b35be

Please sign in to comment.