Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variable duration race in lib/inventory tests #49630

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions lib/inventory/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,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 @@ -400,6 +398,7 @@ func (c *Controller) handleControlStream(handle *upstreamHandle) {
}
}

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