fix: monitorUpstreamConnectionState CPU consumption (#3884)

* fix: monitorUpstreamConnectionState CPU consumption

`monitorUpstreamConnectionState()` is a goroutine that listens for GRPC client connection changes using GRPC's `WaitForStateChange` method. `monitorUpstreamConnectionState()` was consuming the a lot of CPU. It was continuously running and not actually waiting for state changes. The `state` for `monitorUpstreamConnectionState()` was not getting correctly updated which caused the loop to continuously run instead of waiting for new state changes.

Update GRPC `WaitForStateChange` method to use the same `state` that gets updated.
pull/3894/head
Elim Tsiagbey 3 years ago committed by GitHub
parent 1c330543a7
commit 5741807b4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,9 @@ Canonical reference for changes, improvements, and bugfixes for Boundary.
## Next
### Bug Fixes
* monitorUpstreamConnectionState CPU consumption: `monitorUpstreamConnectionState()` is a goroutine that listens for GRPC client connection changes using GRPC's `WaitForStateChange` method. `monitorUpstreamConnectionState()` was consuming the a lot of CPU. It was continuously running and not actually waiting for state changes. The `state` for `monitorUpstreamConnectionState()` was not getting correctly updated which caused the loop to continuously run instead of waiting for new state changes.
## 0.14.1 (2023/10/17)
### Security

@ -434,13 +434,13 @@ func monitorUpstreamConnectionState(ctx context.Context, cc *grpc.ClientConn, co
}
for cc.WaitForStateChange(ctx, state) {
newState := cc.GetState()
state = cc.GetState()
// if the client is shutdown, exit function
if newState == connectivity.Shutdown {
if state == connectivity.Shutdown {
return
}
connectionState.Store(newState)
connectionState.Store(state)
}
}

Loading…
Cancel
Save