Skip to content

Commit

Permalink
fix client issue (#2091)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing authored Jan 24, 2024
1 parent a3e0ba9 commit 3eae9c1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/Proto.Cluster/DefaultClusterContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ public DefaultClusterContext(Cluster cluster)
public async Task<T?> RequestAsync<T>(ClusterIdentity clusterIdentity, object message, ISenderContext context,
CancellationToken ct)
{
if (!_cluster.JoinedCluster.IsCompletedSuccessfully)

//for member requests, we need to wait for the cluster to be ready
if (!_cluster.MemberList.IsClient)
{
await _cluster.JoinedCluster;
if (!_cluster.JoinedCluster.IsCompletedSuccessfully)
{
await _cluster.JoinedCluster;
}
}

var i = 0;

var future = context.GetFuture();
Expand Down
10 changes: 6 additions & 4 deletions src/Proto.Cluster/Member/MemberList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,16 @@ public record MemberList

private TaskCompletionSource<bool> _startedTcs = new(TaskCreationOptions.RunContinuationsAsynchronously);
private IConsensusHandle<ulong>? _topologyConsensus;
private readonly bool _asClient;
private readonly bool _isClient;

public MemberList(Cluster cluster, bool asClient = false)
public bool IsClient => _isClient;

public MemberList(Cluster cluster, bool isClient = false)
{
_cluster = cluster;
_system = _cluster.System;
_root = _system.Root;
_asClient = asClient;
_isClient = isClient;
var (host, port) = _cluster.System.GetAddress();

Self = new Member
Expand Down Expand Up @@ -239,7 +241,7 @@ public void UpdateClusterTopology(IReadOnlyCollection<Member> members)

if (!_startedTcs.Task.IsCompleted)
{
if (_asClient || activeMembers.Contains(_system.Id))
if (_isClient || activeMembers.Contains(_system.Id))
{
_startedTcs.TrySetResult(true);
}
Expand Down

0 comments on commit 3eae9c1

Please sign in to comment.