Skip to content

Commit

Permalink
fix(324): close channel after iterator is closed (#393)
Browse files Browse the repository at this point in the history
Fixed: #324

Signed-off-by: Soren Yang <lsytj0413@gmail.com>
  • Loading branch information
lsytj0413 authored Nov 30, 2023
1 parent 254dc2f commit ef438d9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/leader_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,11 @@ func (lc *leaderController) list(ctx context.Context, request *proto.ListRequest

defer func() {
_ = it.Close()
// NOTE:
// we must close the channel after iterator is closed, to avoid the
// iterator keep open when caller is trying to process the next step (for example db.Close)
// because this is execute in another goroutine.
close(ch)
}()

for ; it.Valid(); it.Next() {
Expand All @@ -638,7 +643,6 @@ func (lc *leaderController) list(ctx context.Context, request *proto.ListRequest
break
}
}
close(ch)
})
}

Expand Down

0 comments on commit ef438d9

Please sign in to comment.