mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-23 21:44:41 +02:00
Fix rpc go routine leak
This commit is contained in:
32
server/rpc_util.go
Normal file
32
server/rpc_util.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// waitgroup for global management of connections
|
||||
type waitGroup struct {
|
||||
// local waitgroup
|
||||
lg sync.WaitGroup
|
||||
// global waitgroup
|
||||
gg *sync.WaitGroup
|
||||
}
|
||||
|
||||
func (w *waitGroup) Add(i int) {
|
||||
w.lg.Add(i)
|
||||
if w.gg != nil {
|
||||
w.gg.Add(i)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *waitGroup) Done() {
|
||||
w.lg.Done()
|
||||
if w.gg != nil {
|
||||
w.gg.Done()
|
||||
}
|
||||
}
|
||||
|
||||
func (w *waitGroup) Wait() {
|
||||
// only wait on local group
|
||||
w.lg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user