fix(agent): prevent metadata from being discarded if report is slow (#10386)

This commit is contained in:
Mathias Fredriksson
2023-10-23 17:02:54 +00:00
committed by GitHub
parent 6683ad989a
commit 1a2aea3a6b
+8 -8
View File
@@ -536,6 +536,14 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
continue
case <-report:
if len(updatedMetadata) > 0 {
select {
case <-reportSemaphore:
default:
// If there's already a report in flight, don't send
// another one, wait for next tick instead.
continue
}
metadata := make([]agentsdk.Metadata, 0, len(updatedMetadata))
for key, result := range updatedMetadata {
metadata = append(metadata, agentsdk.Metadata{
@@ -545,14 +553,6 @@ func (a *agent) reportMetadataLoop(ctx context.Context) {
delete(updatedMetadata, key)
}
select {
case <-reportSemaphore:
default:
// If there's already a report in flight, don't send
// another one, wait for next tick instead.
continue
}
go func() {
ctx, cancel := context.WithTimeout(ctx, reportTimeout)
defer func() {