htrace-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmcc...@apache.org
Subject incubator-htrace git commit: HTRACE-283. Heartbeater should wait for goroutine to finish on close (Masatake Iwasaki via cmccabe)
Date Mon, 26 Oct 2015 21:05:09 GMT
Repository: incubator-htrace
Updated Branches:
  refs/heads/master c28fc60dc -> 2fc552c12


HTRACE-283. Heartbeater should wait for goroutine to finish on close (Masatake Iwasaki via
cmccabe)


Project: http://git-wip-us.apache.org/repos/asf/incubator-htrace/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-htrace/commit/2fc552c1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-htrace/tree/2fc552c1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-htrace/diff/2fc552c1

Branch: refs/heads/master
Commit: 2fc552c12806d226b4863759baa5b2d971609c57
Parents: c28fc60
Author: Colin P. Mccabe <cmccabe@apache.org>
Authored: Mon Oct 26 14:04:45 2015 -0700
Committer: Colin P. Mccabe <cmccabe@apache.org>
Committed: Mon Oct 26 14:04:45 2015 -0700

----------------------------------------------------------------------
 htrace-htraced/go/src/org/apache/htrace/htraced/heartbeater.go | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-htrace/blob/2fc552c1/htrace-htraced/go/src/org/apache/htrace/htraced/heartbeater.go
----------------------------------------------------------------------
diff --git a/htrace-htraced/go/src/org/apache/htrace/htraced/heartbeater.go b/htrace-htraced/go/src/org/apache/htrace/htraced/heartbeater.go
index 140b50d..ea4b053 100644
--- a/htrace-htraced/go/src/org/apache/htrace/htraced/heartbeater.go
+++ b/htrace-htraced/go/src/org/apache/htrace/htraced/heartbeater.go
@@ -22,6 +22,7 @@ package main
 import (
 	"org/apache/htrace/common"
 	"time"
+	"sync"
 )
 
 type Heartbeater struct {
@@ -40,6 +41,8 @@ type Heartbeater struct {
 	// Incoming requests to the heartbeater.  When this is closed, the
 	// heartbeater will exit.
 	req chan *HeartbeatTarget
+
+	wg sync.WaitGroup
 }
 
 type HeartbeatTarget struct {
@@ -62,6 +65,7 @@ func NewHeartbeater(name string, periodMs int64, lg *common.Logger) *Heartbeater
 		targets:  make([]HeartbeatTarget, 0, 4),
 		req:      make(chan *HeartbeatTarget),
 	}
+	hb.wg.Add(1)
 	go hb.run()
 	return hb
 }
@@ -72,6 +76,7 @@ func (hb *Heartbeater) AddHeartbeatTarget(tgt *HeartbeatTarget) {
 
 func (hb *Heartbeater) Shutdown() {
 	close(hb.req)
+	hb.wg.Wait()
 }
 
 func (hb *Heartbeater) String() string {
@@ -94,6 +99,7 @@ func (hb *Heartbeater) run() {
 			select {
 			case tgt, open := <-hb.req:
 				if !open {
+					defer hb.wg.Done()
 					hb.lg.Debugf("%s: exiting.\n", hb.String())
 					return
 				}


Mime
View raw message