From 93f95cdbe6c4fc3abdf4deebb5618d4c8289444d Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Mon, 19 Feb 2024 13:56:34 +0100 Subject: [PATCH 1/3] [Docs] Improve diagrams for hedging cancellation --- docs/strategies/hedging.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/strategies/hedging.md b/docs/strategies/hedging.md index 20b5674f07..515ca0dabf 100644 --- a/docs/strategies/hedging.md +++ b/docs/strategies/hedging.md @@ -144,14 +144,23 @@ sequenceDiagram D-->>D: Processes R2
quickly D->>H: Returns result (R2) deactivate D + deactivate D + H->>D: Propagates cancellation (R1) + activate D + D-->>D: Cancellation of pending actions (R1) + deactivate D + D->>H: Cancellation finished (R1) + deactivate H - deactivate D H->>P: Returns result (R2) P->>C: Returns result (R2) ``` +> [!NOTE] +> Notice that the hedging waits until all additional pending actions are cancelled before returning the accepted result. Therefore it's important for the hedged actions to respect the cancellation token passed to the execution. If the cancellation token is not correctly respected, the hedging is unnecessarily delayed. + ### Fallback mode In fallback mode, the `Delay` value should be less than `TimeSpan.Zero`. This mode allows only a single execution to proceed at a given time. @@ -258,14 +267,22 @@ sequenceDiagram HUC-->>HUC: Processes R2
quickly ... HUC->>-H: Returns result (R2) + deactivate HUC + H->>HUC: Propagates cancellation (R1) + activate HUC + HUC-->>HUC: Cancellation of pending actions (R1) deactivate HUC + HUC->>H: Cancellation finished (R1) deactivate H H->>P: Returns result (R2) P->>C: Returns result (R2) ``` +> [!NOTE] +> Notice that the hedging waits until all additional pending actions are cancelled before returning the accepted result. Therefore it's important for the hedged actions to respect the cancellation token passed to the execution. If the cancellation token is not correctly respected, the hedging is unnecessarily delayed. + #### Parallel: unhappy path sequence diagram The hedging strategy triggers because the `Delay` is set to zero. It fails because all requests fail. From 0d996588b3c0808fa6f1b39b39707be76a07108d Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Mon, 19 Feb 2024 14:47:30 +0100 Subject: [PATCH 2/3] PR comments --- docs/pipelines/index.md | 8 ++++++++ docs/strategies/timeout.md | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/docs/pipelines/index.md b/docs/pipelines/index.md index 63d4f71d13..11fc41a8d6 100644 --- a/docs/pipelines/index.md +++ b/docs/pipelines/index.md @@ -201,6 +201,8 @@ sequenceDiagram deactivate T T-->>T: Times out T->>D: Propagates cancellation + D-->>D: Cancellation of callback + D->>T: Cancellation finished deactivate D T->>R: Throws
TimeoutRejectedException R-->>R: Sleeps @@ -281,6 +283,8 @@ sequenceDiagram T-->>T: Times out T->>R: Propagates cancellation R->>D: Propagates cancellation + D-->>D: Cancellation of callback + D->>T: Cancellation finished deactivate D T->>P: Throws
TimeoutRejectedException @@ -348,6 +352,8 @@ sequenceDiagram deactivate TI Note over TI: Wait end TI->>D: Propagates cancellation + D-->>D: Cancellation of callback + D->>TI: Cancellation finished deactivate D TI->>R: Throws
TimeoutRejectedException @@ -365,6 +371,8 @@ sequenceDiagram TO->>R: Propagates cancellation R->>TI: Propagates cancellation TI->>D: Propagates cancellation + D-->>D: Cancellation of callback + D->>TO: Cancellation finished deactivate TI deactivate D TO->>P: Throws
TimeoutRejectedException diff --git a/docs/strategies/timeout.md b/docs/strategies/timeout.md index 961a1e6bb4..e5cbcd356d 100644 --- a/docs/strategies/timeout.md +++ b/docs/strategies/timeout.md @@ -165,12 +165,19 @@ sequenceDiagram D-->>D: Performs
long-running
operation T-->>T: Times out deactivate T + T->>D: Propagates cancellation + D-->>D: Cancellation of callback + D->>T: Cancellation finished deactivate D + T->>P: Throws
TimeoutRejectedException P->>C: Propagates exception ``` +> [!NOTE] +> Notice that the timeout waits until the callback is cancelled before throwing `TimeoutRejectedException`. Therefore it's important for the callbacks to respect the cancellation token passed to the execution. If the cancellation token is not correctly respected, the timeout is unnecessarily delayed. + ## Anti-patterns Over the years, many developers have used Polly in various ways. Some of these From c271d57308563d874a91aa29ff38e6503c92efd4 Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Mon, 19 Feb 2024 15:07:42 +0100 Subject: [PATCH 3/3] PR comments --- docs/strategies/timeout.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/strategies/timeout.md b/docs/strategies/timeout.md index e5cbcd356d..66753fa71a 100644 --- a/docs/strategies/timeout.md +++ b/docs/strategies/timeout.md @@ -175,8 +175,8 @@ sequenceDiagram P->>C: Propagates exception ``` -> [!NOTE] -> Notice that the timeout waits until the callback is cancelled before throwing `TimeoutRejectedException`. Therefore it's important for the callbacks to respect the cancellation token passed to the execution. If the cancellation token is not correctly respected, the timeout is unnecessarily delayed. +> [!IMPORTANT] +> Notice that the timeout waits until the callback is cancelled before throwing `TimeoutRejectedException`. Therefore it's important for the callbacks to respect the cancellation token passed to the execution. If the cancellation token is not correctly respected, the timeout is unnecessarily delayed. ## Anti-patterns