Skip to content

Cluster.LeaveAsync()  #2280

@kostrse

Description

@kostrse

Currently, to leave cluster before termination one needs to subscribe to RegisterOnMemberRemoved, do Leave(cluster.SelfAddress) and wait for member removal event.

This pattern is very easy to implement wrong. There are also edge cases when event doesn't guarantee arrive (member is in Joining state etc.), thus very easy to hang the process.

Situation becomes more complicated with support of CancellationToken etc.

I'd want to propose to add a convenience method Task LeaveAsync() into the Cluster.

The example code could look like this:

// with or without cancellation token
await Cluster.Get(_actorSystem).LeaveAsync(cancellationToken);
await _actorSystem.Terminate();

Naive implementation as extension method, just for reference:

public static Task LeaveAsync(this Cluster cluster)
{
    var tcs = new TaskCompletionSource<bool>();

    cluster.RegisterOnMemberRemoved(() => { tcs.TrySetResult(true); });
    cluster.Leave(cluster.SelfAddress);

    return tcs.Task;
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions