Skip to content

Commit

Permalink
fix: Block waitTillReady (#13)
Browse files Browse the repository at this point in the history
* fix: Block waitTillReady

Previous implementation is async and hence the code doesn't really wait till the cache is ready.

This results in InternalServerExceptions on first Set.

* fix: review comments
  • Loading branch information
gautamomento authored Nov 2, 2021
1 parent 50ea72d commit 596db7b
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Momento/MomentoCache.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using CacheClient;
using static CacheClient.Scs;
using Grpc.Core;
Expand Down Expand Up @@ -241,9 +242,10 @@ private ByteString Convert(String s)
return ByteString.CopyFromUtf8(s);
}

private async void WaitUntilReady()
// Temporary measure. Till the metadata stream is up and running.
private void WaitUntilReady()
{
ByteString cacheKey = ByteString.CopyFromUtf8("matt");
ByteString cacheKey = ByteString.CopyFromUtf8(Guid.NewGuid().ToString());
GetRequest request = new GetRequest() { CacheKey = cacheKey };
Exception lastError = new Exception();
int backoffMillis = 50;
Expand All @@ -261,12 +263,11 @@ private async void WaitUntilReady()
catch (Exception e)
{
lastError = e;
await Task.Delay(backoffMillis);
Thread.Sleep(backoffMillis);
}

}

throw lastError;
throw CacheExceptionMapper.Convert(lastError);
}

private long GetUnixTime()
Expand Down

0 comments on commit 596db7b

Please sign in to comment.