From 5741807b4abdb8fe4ce7d446681ea6f6876b7cdb Mon Sep 17 00:00:00 2001 From: Elim Tsiagbey Date: Mon, 23 Oct 2023 19:35:12 -0400 Subject: [PATCH] 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. --- CHANGELOG.md | 3 +++ internal/daemon/worker/controller_connection.go | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4f39af113..308c1f9b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/internal/daemon/worker/controller_connection.go b/internal/daemon/worker/controller_connection.go index 2dc2a2f636..e2c566c922 100644 --- a/internal/daemon/worker/controller_connection.go +++ b/internal/daemon/worker/controller_connection.go @@ -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) } }