Skip to content

Commit 516a7a7

Browse files
authored
Fix race in shutdown of AWS Container Insight receiver (#37695)
#### Description Fix race condition during the shutdown of the AWS Container Insight receiver. Found by code inspection. #### Documentation Changelog.
1 parent d3d6061 commit 516a7a7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
change_type: bug_fix
2+
3+
component: awscontainerinsightreceiver
4+
5+
note: Fix race condition in shutdown of AWS Container Insight receiver
6+
7+
issues: [37695]
8+
9+
change_logs: [user]

receiver/awscontainerinsightreceiver/receiver.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package awscontainerinsightreceiver // import "github.com/open-telemetry/opentel
66
import (
77
"context"
88
"errors"
9+
"sync"
910
"time"
1011

1112
"go.opentelemetry.io/collector/component"
@@ -35,6 +36,7 @@ type awsContainerInsightReceiver struct {
3536
nextConsumer consumer.Metrics
3637
config *Config
3738
cancel context.CancelFunc
39+
cancelWg sync.WaitGroup
3840
cadvisor metricsProvider
3941
k8sapiserver metricsProvider
4042
}
@@ -92,7 +94,10 @@ func (acir *awsContainerInsightReceiver) Start(ctx context.Context, host compone
9294
}
9395
}
9496

97+
acir.cancelWg.Add(1)
9598
go func() {
99+
defer acir.cancelWg.Done()
100+
96101
// cadvisor collects data at dynamical intervals (from 1 to 15 seconds). If the ticker happens
97102
// at beginning of a minute, it might read the data collected at end of last minute. To avoid this,
98103
// we want to wait until at least two cadvisor collection intervals happens before collecting the metrics
@@ -122,6 +127,7 @@ func (acir *awsContainerInsightReceiver) Shutdown(context.Context) error {
122127
return nil
123128
}
124129
acir.cancel()
130+
acir.cancelWg.Wait()
125131

126132
var errs error
127133

0 commit comments

Comments
 (0)