diff --git a/agent/agent.go b/agent/agent.go index 93daba559c49e..7f7e8cd64dff8 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -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() {