Skip to content

fix: guard MoveToStandbyState in async void transition methods#282

Closed
Qian-Cheng-nju wants to merge 1 commit intodotnet:masterfrom
specula-org:fix/guard-standby-fallback
Closed

fix: guard MoveToStandbyState in async void transition methods#282
Qian-Cheng-nju wants to merge 1 commit intodotnet:masterfrom
specula-org:fix/guard-standby-fallback

Conversation

@Qian-Cheng-nju
Copy link
Copy Markdown
Contributor

@Qian-Cheng-nju Qian-Cheng-nju commented Mar 27, 2026

Hi, thanks for dotNext again!

The three async void state transition methods (MoveToFollowerState, MoveToCandidateState, MoveToLeaderState) call MoveToStandbyState() in their catch blocks as a fallback. If MoveToStandbyState() itself throws (e.g., DisposeAsync failure during UpdateStateAsync), the exception escapes the async void method and crashes the process via the unobserved exception handler.

This wraps each MoveToStandbyState() fallback in a try-catch so the exception is logged instead of crashing.

@Qian-Cheng-nju
Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree [company="{Nanjing University}"]

@Qian-Cheng-nju
Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree company="Nanjing University"

@sakno
Copy link
Copy Markdown
Collaborator

sakno commented Mar 28, 2026

DisposeAsync as well as Dispose must be idempotent and exception-free. This is recommended not only for Raft, it is for all implementations of IDisposable and IAsyncDisposable interfaces. In .NEXT Raft, every Raft state is designed in that way. It's better to analyze their implementations to achieve the necessary behavior rather than assuming the exception.

@Qian-Cheng-nju
Copy link
Copy Markdown
Contributor Author

You're right — I checked all four state implementations and their DisposeAsyncCore() methods are fully guarded with try-catch-finally. There's no path that can throw. Thanks for the explanation!

@sakno sakno added this to Cluster Mar 28, 2026
@github-project-automation github-project-automation bot moved this to Opened in Cluster Mar 28, 2026
@sakno sakno added the Lib:Cluster DotNext.Net.Cluster library label Mar 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Lib:Cluster DotNext.Net.Cluster library

Projects

Status: Opened

Development

Successfully merging this pull request may close these issues.

2 participants