Skip to content

Commit

Permalink
fix OOM (#32)
Browse files Browse the repository at this point in the history
Calling electionHandler.Observe(e.ctx) within a for loop continuously creates goroutines, leading to an OOM (Out Of Memory) issue.
  • Loading branch information
P2YH authored Jul 25, 2024
1 parent 30fe483 commit 356e735
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion elector.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,10 @@ func (e *Elector) Start(electionPath string) error {
e.unsetLeader("")
}()

ch := electionHandler.Observe(e.ctx)
for e.ctx.Err() == nil {
select {
case resp := <-electionHandler.Observe(e.ctx):
case resp := <-ch:
if len(resp.Kvs) == 0 {
continue
}
Expand Down

0 comments on commit 356e735

Please sign in to comment.