Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.

Commit 7ff3d50

Browse files
committed
create channel outside the tomb
1 parent 5a51a81 commit 7ff3d50

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

agent/recorder.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ func NewSpanRecorder(agent *Agent) *SpanRecorder {
101101
r.stats = &RecorderStats{}
102102
r.logger.Printf("recorder frequency: %v", agent.flushFrequency)
103103
r.logger.Printf("recorder concurrency level: %v", agent.concurrencyLevel)
104+
105+
// start workers
106+
r.workerJobs = make(chan *workerJob, r.concurrencyLevel)
107+
r.workerResults = make(chan *workerResult, r.concurrencyLevel)
108+
for i := 0; i < r.concurrencyLevel; i++ {
109+
go r.worker(i + 1)
110+
}
104111
r.t.Go(r.loop)
105112
return r
106113
}
@@ -122,18 +129,8 @@ func (r *SpanRecorder) RecordSpan(span tracer.RawSpan) {
122129

123130
func (r *SpanRecorder) loop() error {
124131
defer func() {
125-
close(r.workerJobs)
126-
close(r.workerResults)
127132
r.logger.Println("recorder has been stopped.")
128133
}()
129-
130-
// start workers
131-
r.workerJobs = make(chan *workerJob, r.concurrencyLevel)
132-
r.workerResults = make(chan *workerResult, r.concurrencyLevel)
133-
for i := 0; i < r.concurrencyLevel; i++ {
134-
go r.worker(i + 1)
135-
}
136-
137134
ticker := time.NewTicker(1 * time.Second)
138135
cTime := time.Now()
139136
for {
@@ -280,6 +277,8 @@ func (r *SpanRecorder) Stop() {
280277
}
281278
r.t.Kill(nil)
282279
_ = r.t.Wait()
280+
close(r.workerJobs)
281+
close(r.workerResults)
283282
if r.debugMode {
284283
r.writeStats()
285284
}

0 commit comments

Comments
 (0)