Skip to content

Commit

Permalink
Fix hang when using listen-events
Browse files Browse the repository at this point in the history
Signed-off-by: Enwei Jiao <enwei.jiao@zilliz.com>
  • Loading branch information
jiaoew1991 committed Oct 17, 2023
1 parent 2794834 commit 8fd0af0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion states/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,11 @@ func (s *InstanceState) prepareListenerClients(ctx context.Context) ([]*eventlog

var m sync.Map
var wg sync.WaitGroup
wg.Add(len(sessions))

sessions = lo.UniqBy[*models.Session, int64](sessions, func(session *models.Session) int64 {
return session.ServerID
})
wg.Add(len(sessions))
for _, session := range sessions {
go func(session *models.Session) {
defer wg.Done()
Expand Down Expand Up @@ -200,6 +203,16 @@ func (s *InstanceState) prepareListenerClients(ctx context.Context) ([]*eventlog

wg.Wait()

mSize := 0
m.Range(func(_, _ any) bool {
mSize++
return true
})

if mSize != len(sessions) {
return nil, fmt.Errorf("failed to create listener, expected %d, got %d", len(sessions), mSize)
}

var listeners []*eventlog.Listener
m.Range(func(key, value any) bool {
listener := value.(*eventlog.Listener)
Expand Down

0 comments on commit 8fd0af0

Please sign in to comment.