Skip to content

Throttle repeated cloud proxy rebuilds - #7536

Open
yophilav wants to merge 4 commits into
mainfrom
fix/7535-cloud-proxy-rebuild-cooldown
Open

Throttle repeated cloud proxy rebuilds#7536
yophilav wants to merge 4 commits into
mainfrom
fix/7535-cloud-proxy-rebuild-cooldown

Conversation

@yophilav

@yophilav yophilav commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Five-second per-device cooldown for failed or rapidly inactive cloud proxy creation; initial creation and first replacement immediate.
  • Typed monotonic retry timing using an elapsed TimeSpan, avoiding wall-clock and raw tick-unit coupling.
  • Active connection state separated from a preserved pending-token handoff so normal lookup cannot return the handoff slot.
  • Explicit generation/removal invariants and serialized removal so stale creation/update results are discarded.
  • Shared creation task published under the state lock, while caller-supplied asynchronous creation starts only after releasing that lock.
  • Atomic TaskCompletionSource token waiter lifecycle, stale callback suppression, and cancel-before-close cleanup for discarded connections.
  • Deterministic token-retry tests through a narrow injected delay seam instead of fixed sleeps.

Fixes #7535

Testing

  • ConnectionManagerTest and RetryingCloudProxyTest: 34 passed
  • ClientTokenCloudConnectionTest: 9 passed
  • .NET 10 CheckInBuild / StyleCop: passed
  • Six-model principal-engineer panel: satisfied

yophilav and others added 4 commits August 6, 2026 17:22
Reuse recently completed retry connection attempts per device so queued operations cannot trigger a sequential rebuild stampede when replacements immediately become inactive.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0b428cdd-2248-4f74-87b1-cd02dc9ad50a
Coalesce failed per-device rebuild attempts, fence concurrent removals, and preserve token handoff without exposing stale connections to normal lookup.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0b428cdd-2248-4f74-87b1-cd02dc9ad50a
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0b428cdd-2248-4f74-87b1-cd02dc9ad50a
Make retry timing and generation invariants explicit, avoid starting asynchronous creation under the state lock, and replace fixed-delay token tests with deterministic synchronization.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 0b428cdd-2248-4f74-87b1-cd02dc9ad50a

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Edge Hub’s cloud-connection management to prevent “stampede” rebuilds of per-device cloud proxies during upstream outages by introducing per-device creation throttling and stronger invariants around creation/removal lifecycles. It also hardens token-refresh behavior so discarded connections don’t keep accepting or delivering tokens, and adds deterministic unit tests around these new behaviors.

Changes:

  • Add per-device cooldown/throttle behavior for repeated failed or immediately-inactive cloud connection creation in ConnectionManager.
  • Introduce preserved-connection semantics for token-handoff plus serialized cloud-connection removal with generation invalidation to discard stale create/update results.
  • Add cancelable token update lifecycle in ClientTokenCloudConnection, plus new unit tests to validate cancellation and throttling behavior.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Core/ConnectionManager.cs Implements per-device cloud-connection creation throttling, preserves token-handoff state, and serializes/removes with generation-based invalidation.
edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.Core/cloud/IClientTokenCloudConnection.cs Extends the cloud-connection token interface to expose pending-token state and allow cancellation.
edge-hub/core/src/Microsoft.Azure.Devices.Edge.Hub.CloudProxy/ClientTokenCloudConnection.cs Implements cancelable token waiter lifecycle and suppresses token-status callbacks after cancellation.
edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.Core.Test/ConnectionManagerTest.cs Adds tests validating throttling and removal/invalidated in-flight connection behavior.
edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.Core.Test/RetryingCloudProxyTest.cs Updates tests to inject a monotonic clock and disable retry delay for determinism.
edge-hub/core/test/Microsoft.Azure.Devices.Edge.Hub.CloudProxy.Test/ClientTokenCloudConnectionTest.cs Adds tests ensuring cancellation rejects token requests and suppresses callbacks during retry.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +9 to 13
bool HasPendingTokenUpdate { get; }

void CancelTokenUpdate();

Task<ICloudProxy> UpdateTokenAsync(ITokenCredentials tokenCredentials);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants