grpcproxy: don't leak goroutines on watch proxy shutdown

This commit is contained in:
Anthony Romano 2016-07-23 14:13:38 -07:00
parent 418bb5e176
commit 2b4c37f54a
2 changed files with 19 additions and 0 deletions

View File

@ -82,7 +82,18 @@ type serverWatchStream struct {
nextWatcherID int64
}
func (sws *serverWatchStream) close() {
close(sws.watchCh)
close(sws.ctrlCh)
for _, ws := range sws.singles {
ws.stop()
}
sws.groups.stop()
}
func (sws *serverWatchStream) recvLoop() error {
defer sws.close()
for {
req, err := sws.gRPCStream.Recv()
if err == io.EOF {

View File

@ -86,3 +86,11 @@ func (wgs *watchergroups) maybeJoinWatcherSingle(rid receiverID, ws watcherSingl
return false
}
func (wgs *watchergroups) stop() {
wgs.mu.Lock()
defer wgs.mu.Unlock()
for _, wg := range wgs.groups {
wg.stop()
}
}