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

[Docs] Improve diagrams for hedging cancellation #1975

Merged
merged 3 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions docs/pipelines/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <br/>TimeoutRejectedException
R-->>R: Sleeps
Expand Down Expand Up @@ -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 <br/>TimeoutRejectedException
Expand Down Expand Up @@ -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 <br/>TimeoutRejectedException

Expand All @@ -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 <br/>TimeoutRejectedException
Expand Down
19 changes: 18 additions & 1 deletion docs/strategies/hedging.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,23 @@ sequenceDiagram
D-->>D: Processes R2<br/> 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.
Expand Down Expand Up @@ -258,14 +267,22 @@ sequenceDiagram
HUC-->>HUC: Processes R2<br/> 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.
Expand Down
7 changes: 7 additions & 0 deletions docs/strategies/timeout.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,19 @@ sequenceDiagram
D-->>D: Performs <br/>long-running <br/>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 <br/>TimeoutRejectedException
P->>C: Propagates exception
```

> [!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

Over the years, many developers have used Polly in various ways. Some of these
Expand Down