Skip to content

Commit

Permalink
Fix variable duration race in lib/inventory tests (#49657)
Browse files Browse the repository at this point in the history
  • Loading branch information
espadolini authored Dec 2, 2024
1 parent ca48498 commit 65f6d87
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/inventory/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,11 @@ func (c *Controller) RegisterControlStream(stream client.UpstreamInventoryContro
c.store.Insert(handle)

// Increment the concurrent connection counter that we use to calculate the
// variable instance heartbeat duration. It's done here synchronously rather
// than in handleControlStream for the sake of tests.
// variable instance heartbeat duration. To make the behavior more easily
// testable, we increment it here and we decrement it before closing the
// stream in handleControlStream.
c.instanceHBVariableDuration.Inc()
go func() {
defer c.instanceHBVariableDuration.Dec()
c.handleControlStream(handle)
}()
go c.handleControlStream(handle)
}

// GetControlStream gets a control stream for the given server ID if one exists (if multiple control streams
Expand Down Expand Up @@ -375,6 +373,7 @@ func (c *Controller) handleControlStream(handle *upstreamHandle) {
}
}

c.instanceHBVariableDuration.Dec()
for _, service := range handle.hello.Services {
c.serviceCounter.decrement(service)
}
Expand Down

0 comments on commit 65f6d87

Please sign in to comment.