Skip to content

Commit

Permalink
Fix go routine leaks when consumer close with msg channel blocked (#642)
Browse files Browse the repository at this point in the history
Co-authored-by: zhangxu16 <[email protected]>
  • Loading branch information
maixiaohai and zhangxu16 authored Jun 17, 2021
1 parent 9768869 commit c688c19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ func (dc *defaultConsumer) shutdown() error {
k := key.(primitive.MessageQueue)
pq := value.(*processQueue)
pq.WithDropped(true)
// close msg channel using RWMutex to make sure no data was writing
pq.mutex.Lock()
close(pq.msgCh)
pq.mutex.Unlock()
mqs = append(mqs, &k)
return true
})
Expand Down
4 changes: 4 additions & 0 deletions consumer/process_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ func (pq *processQueue) putMessage(messages ...*primitive.MessageExt) {
return
}
pq.mutex.Lock()
if pq.IsDroppd() {
pq.mutex.Unlock()
return
}
if !pq.order {
pq.msgCh <- messages
}
Expand Down

0 comments on commit c688c19

Please sign in to comment.