Skip to content
/ etcd Public
forked from etcd-io/etcd

Commit

Permalink
Merge pull request etcd-io#7103 from heyitsanthony/proxy-watch-close
Browse files Browse the repository at this point in the history
grpcproxy: tear down watch when client context is done
  • Loading branch information
Anthony Romano authored Jan 5, 2017
2 parents fd72ecf + e179225 commit 5feb4e1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions proxy/grpcproxy/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,23 @@ func (wp *watchProxy) Watch(stream pb.Watch_WatchServer) (err error) {
defer func() { stopc <- struct{}{} }()
wps.sendLoop()
}()
if leaderc != nil {
go func() {
defer func() { stopc <- struct{}{} }()
select {
case <-leaderc:
case <-ctx.Done():
}
}()
}
// tear down watch if leader goes down or entire watch proxy is terminated
go func() {
defer func() { stopc <- struct{}{} }()
select {
case <-leaderc:
case <-ctx.Done():
case <-wp.ctx.Done():
}
}()

<-stopc
cancel()

// recv/send may only shutdown after function exits;
// goroutine notifies proxy that stream is through
go func() {
if leaderc != nil {
<-stopc
}
<-stopc
<-stopc
wps.close()
wp.wg.Done()
Expand Down

0 comments on commit 5feb4e1

Please sign in to comment.