Possible reasons and correct handling of TableStorageUpdateConditionNotSatisfiedException
Hi All,
I noticed we're getting TableStorageUpdateConditionNotSatisfiedException and I'm wondering whether we're doing anything wrong or there's an issue in Orleans.
It seems that the exception can be thrown in any grain that calls WriteStateAsync.
Exceptions are as follows:
Error from storage provider AzureTableGrainStorage.MyNamespace.OrleansSilo.GrainsCollection.PlateRecognizer.PlateDeduplicationGrain during WriteState for grain Type=MyNamespace.OrleansSilo.GrainsCollection.PlateRecognizer.PlateDeduplicationGrain Pk=*grn/A67DBB61/0000000000000000000000000000000006ffffffa67dbb61+226399::1-0x14215DB0 Id=GrainReference:*grn/A67DBB61/00000000+226399::1 Error=UpdateConditionNotSatisfied
Exc level 0: Orleans.Storage.TableStorageUpdateConditionNotSatisfiedException: Table storage condition not Satisfied. GrainType: MyNamespace.OrleansSilo.GrainsCollection.PlateRecognizer.PlateDeduplicationGrain, GrainId: GrainReference:*grn/A67DBB61/00000000+226399::1, TableName: OrleansGrainState, StoredETag: Unknown, CurrentETag: W/"datetime'2018-10-18T16%3A45%3A04.1338014Z'"
at Orleans.Storage.AzureTableGrainStorage.DoOptimisticUpdate(Func`1 updateOperation, String grainType, GrainReference grainReference, String tableName, String currentETag)
at Orleans.Storage.AzureTableGrainStorage.WriteStateAsync(String grainType, GrainReference grainReference, IGrainState grainState)
at Orleans.Core.StateStorageBridge`1.WriteStateAsync()
Exc level 1: Microsoft.WindowsAzure.Storage.StorageException: Message = Precondition Failed, HttpStatusCode = 412, HttpStatusMessage = Precondition Failed, ExtendedErrorInformation.ErrorCode = UpdateConditionNotSatisfied, ExtendedErrorInformation.ErrorMessage = The update condition specified in the request was not satisfied.
RequestId:a048cff3-6002-0039-2503-67bdc9000000
Time:2018-10-18T16:57:55.8897711Z.
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Orleans.Persistence.AzureStorage.AzureTableDataManager`1.UpdateTableEntryAsync(T data, String dataEtag)
at Orleans.Storage.AzureTableGrainStorage.GrainStateTableDataManager.Write(GrainStateRecord record)
at Orleans.Storage.AzureTableGrainStorage.DoOptimisticUpdate(Func`1 updateOperation, String grainType, GrainReference grainReference, String tableName, String currentETag)
InconsistentStateException: Table storage condition not Satisfied. GrainType: MyNamespace.OrleansSilo.GrainsCollection.PlateRecognizer.PlateDeduplicationGrain, GrainId: GrainReference:*grn/A67DBB61/00000000+226399::1, TableName: OrleansGrainState, StoredETag: Unknown, CurrentETag: W/"datetime'2018-10-18T16%3A45%3A04.1338014Z'" Expected Etag=Unknown Received Etag=W/"datetime'2018-10-18T16%3A45%3A04.1338014Z'" Microsoft.WindowsAzure.Storage.StorageException: Precondition Failed
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Orleans.Persistence.AzureStorage.AzureTableDataManager`1.UpdateTableEntryAsync(T data, String dataEtag)
at Orleans.Storage.AzureTableGrainStorage.GrainStateTableDataManager.Write(GrainStateRecord record)
at Orleans.Storage.AzureTableGrainStorage.DoOptimisticUpdate(Func`1 updateOperation, String grainType, GrainReference grainReference, String tableName, String currentETag)
Request Information
RequestID:a048cff3-6002-0039-2503-67bdc9000000
RequestDate:Thu, 18 Oct 2018 16:57:55 GMT
StatusMessage:Precondition Failed
ErrorCode:UpdateConditionNotSatisfied
ErrorMessage:The update condition specified in the request was not satisfied.
RequestId:a048cff3-6002-0039-2503-67bdc9000000
Time:2018-10-18T16:57:55.8897711Z
The only difference from the standard that we have is that all grains inherit the same base grain class:
public class GrainWithMetrics<T>: Grain<T> where T : new()
{
private readonly string _typeName;
public GrainWithMetrics()
{
_typeName = GetType().Name;
}
protected override Task ReadStateAsync()
{
return base.ReadStateAsync()
.WithStopwatchAsync($"{_typeName}::ReadState", Metrics.StopwatchObserver);
}
protected override Task WriteStateAsync()
{
return base.WriteStateAsync()
.WithStopwatchAsync($"{_typeName}::WriteState", Metrics.StopwatchObserver);
}
}
Where WithStopwatchAsync does just something like this:
public static async Task<T> WithStopwatchAsync<T>(
this Task<T> task,
[NotNull] Action<TimeSpan> onTaskFinished)
{
if (task == null) return default(T);
if (onTaskFinished == null) throw new ArgumentNullException(nameof(onTaskFinished));
var sw = new Stopwatch();
sw.Start();
try { return await task; }
finally
{
sw.Stop();
try { onTaskFinished(sw.Elapsed); }
catch (Exception e)
{
Trace.TraceError(
$"Errror calling {nameof(onTaskFinished)} in {nameof(StopwatchExtensions)}.{nameof(WithStopwatchAsync)}:\n{e}");
}
}
}
We're running Orleans 2.0.5.
Any help would be hugely appreciated, thanks in advance.
I wonder if this is because of #5003.
it is possible that this is related to #5003 . @ilyalukyanov can you go to that issue and see if any symptom there is also something you have observed ?
Thanks @sergeybykov @xiazen. I have some of the symptoms, but not sure if all are parts of the same issue or different issues.
Below are exceptions I'm seeing.
1. For reminders
2018-10-25T15:18:17.9905283Z [Runtime.Scheduler.WorkerPoolThread/3] ERROR production orleans-silo-2 10.245.5.58 Orleans.Runtime.GrainTimer [ActivityId=00000000-0000-0000-0000-000000000000] {log4net:Identity=NOT AVAILABLE, log4net:UserName=NOT AVAILABLE, EventID=101413, log4net:HostName=orleans-silo-2} - Caught and ignored exception: Orleans.Runtime.OrleansException with mesagge: Failed to read Azure storage table OrleansReminders: An item with the same key has already been added. Key: timeout thrown from timer callback GrainTimer.ReminderService.ReminderListRefresher. TimerCallbackHandler:[LowPrioritySystemTarget: S10.245.5.58:11111:278160901*stg/0/00000000@S00000000]->System.Threading.Tasks.Task <PromoteToStarted>b__26_0(System.Object)
Orleans.Runtime.OrleansException: Failed to read Azure storage table OrleansReminders: An item with the same key has already been added. Key: timeout ---> Microsoft.WindowsAzure.Storage.StorageException: An item with the same key has already been added. Key: timeout ---> System.ArgumentException: An item with the same key has already been added. Key: timeout
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.CreateRequestMessage(HttpMethod method, Uri uri, Nullable`1 timeout, UriQueryBuilder builder, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestCore(Uri uri, UriQueryBuilder builder, HttpMethod method, Nullable`1 timeout, HttpContent content, OperationContext ctx, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, HttpContent content, OperationContext ctx, TablePayloadFormat payloadFormat, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass24_0`2.<QueryImpl>b__0(RESTCommand`1 cmd, Uri uri, UriQueryBuilder queryBuilder, HttpContent cnt, Nullable`1 serverTimeout, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass20_0.<<ExecuteQuerySegmentedAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.<>c__DisplayClass27_0.<<ReadTableEntriesAndEtagsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
--- End of inner exception stack trace ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
at Orleans.Runtime.ReminderService.RemindersTableManager.FindReminderEntries(UInt32 begin, UInt32 end)
at Orleans.Runtime.ReminderService.AzureBasedReminderTable.ReadRows(UInt32 begin, UInt32 end)
at Orleans.Runtime.ReminderService.LocalReminderService.ReadTableAndStartTimers(IRingRange range, Int32 rangeSerialNumberCopy)
at Orleans.Runtime.ReminderService.LocalReminderService.ReadAndUpdateReminders()
at Orleans.Runtime.GrainTimer.ForwardToAsyncCallback(Object state)
2018-10-25T15:18:17.9888790Z [Runtime.Scheduler.WorkerPoolThread/3] WARN production orleans-silo-2 10.245.5.58 Orleans.Runtime.ReminderService.AzureBasedReminderTable [ActivityId=00000000-0000-0000-0000-000000000000] {log4net:Identity=NOT AVAILABLE, log4net:UserName=NOT AVAILABLE, EventID=100840, log4net:HostName=orleans-silo-2} - Intermediate error reading reminders in range <(x3D90693B x3DA0163A], Size=x000FACFF, %Ring=0.024%> for table OrleansReminders.
Orleans.Runtime.OrleansException: Failed to read Azure storage table OrleansReminders: An item with the same key has already been added. Key: timeout ---> Microsoft.WindowsAzure.Storage.StorageException: An item with the same key has already been added. Key: timeout ---> System.ArgumentException: An item with the same key has already been added. Key: timeout
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.CreateRequestMessage(HttpMethod method, Uri uri, Nullable`1 timeout, UriQueryBuilder builder, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestCore(Uri uri, UriQueryBuilder builder, HttpMethod method, Nullable`1 timeout, HttpContent content, OperationContext ctx, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, HttpContent content, OperationContext ctx, TablePayloadFormat payloadFormat, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass24_0`2.<QueryImpl>b__0(RESTCommand`1 cmd, Uri uri, UriQueryBuilder queryBuilder, HttpContent cnt, Nullable`1 serverTimeout, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass20_0.<<ExecuteQuerySegmentedAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.<>c__DisplayClass27_0.<<ReadTableEntriesAndEtagsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
--- End of inner exception stack trace ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
at Orleans.Runtime.ReminderService.RemindersTableManager.FindReminderEntries(UInt32 begin, UInt32 end)
at Orleans.Runtime.ReminderService.AzureBasedReminderTable.ReadRows(UInt32 begin, UInt32 end)
2018-10-25T15:18:17.9878666Z [Runtime.Scheduler.WorkerPoolThread/3] WARN production orleans-silo-2 10.245.5.58 Orleans.Reminders.AzureStorage.AzureTableDataManager [ActivityId=00000000-0000-0000-0000-000000000000] {log4net:Identity=NOT AVAILABLE, log4net:UserName=NOT AVAILABLE, EventID=100809, log4net:HostName=orleans-silo-2} - Failed to read Azure storage table OrleansReminders: An item with the same key has already been added. Key: timeout
Microsoft.WindowsAzure.Storage.StorageException: An item with the same key has already been added. Key: timeout ---> System.ArgumentException: An item with the same key has already been added. Key: timeout
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.CreateRequestMessage(HttpMethod method, Uri uri, Nullable`1 timeout, UriQueryBuilder builder, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestCore(Uri uri, UriQueryBuilder builder, HttpMethod method, Nullable`1 timeout, HttpContent content, OperationContext ctx, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, HttpContent content, OperationContext ctx, TablePayloadFormat payloadFormat, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass24_0`2.<QueryImpl>b__0(RESTCommand`1 cmd, Uri uri, UriQueryBuilder queryBuilder, HttpContent cnt, Nullable`1 serverTimeout, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass20_0.<<ExecuteQuerySegmentedAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.<>c__DisplayClass27_0.<<ReadTableEntriesAndEtagsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
Request Information
RequestID:
RequestDate:
StatusMessage:
2018-10-25T15:18:17.9873804Z [Runtime.Scheduler.WorkerPoolThread/3] ERROR production orleans-silo-2 10.245.5.58 Orleans.Reminders.AzureStorage.AzureTableDataManager [ActivityId=00000000-0000-0000-0000-000000000000] {log4net:Identity=NOT AVAILABLE, log4net:UserName=NOT AVAILABLE, EventID=100812, log4net:HostName=orleans-silo-2} - Unexpected issue reading Azure storage table OrleansReminders: Exception Type=System.ArgumentException Message='An item with the same key has already been added. Key: timeout'
System.ArgumentException: An item with the same key has already been added. Key: timeout
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.CreateRequestMessage(HttpMethod method, Uri uri, Nullable`1 timeout, UriQueryBuilder builder, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestCore(Uri uri, UriQueryBuilder builder, HttpMethod method, Nullable`1 timeout, HttpContent content, OperationContext ctx, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, HttpContent content, OperationContext ctx, TablePayloadFormat payloadFormat, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass24_0`2.<QueryImpl>b__0(RESTCommand`1 cmd, Uri uri, UriQueryBuilder queryBuilder, HttpContent cnt, Nullable`1 serverTimeout, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
2018-10-25T15:18:17.9896368Z [Runtime.Scheduler.WorkerPoolThread/3] ERROR production orleans-silo-2 10.245.5.58 Orleans.Runtime.ReminderService.LocalReminderService [ActivityId=00000000-0000-0000-0000-000000000000] {log4net:Identity=NOT AVAILABLE, log4net:UserName=NOT AVAILABLE, EventID=102920, log4net:HostName=orleans-silo-2} - Failed to read rows from table.
Orleans.Runtime.OrleansException: Failed to read Azure storage table OrleansReminders: An item with the same key has already been added. Key: timeout ---> Microsoft.WindowsAzure.Storage.StorageException: An item with the same key has already been added. Key: timeout ---> System.ArgumentException: An item with the same key has already been added. Key: timeout
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at Microsoft.WindowsAzure.Storage.Shared.Protocol.HttpRequestMessageFactory.CreateRequestMessage(HttpMethod method, Uri uri, Nullable`1 timeout, UriQueryBuilder builder, HttpContent content, OperationContext operationContext, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestCore(Uri uri, UriQueryBuilder builder, HttpMethod method, Nullable`1 timeout, HttpContent content, OperationContext ctx, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.Protocol.TableOperationHttpRequestMessageFactory.BuildRequestForTableQuery(Uri uri, UriQueryBuilder builder, Nullable`1 timeout, HttpContent content, OperationContext ctx, TablePayloadFormat payloadFormat, ICanonicalizer canonicalizer, StorageCredentials credentials)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass24_0`2.<QueryImpl>b__0(RESTCommand`1 cmd, Uri uri, UriQueryBuilder queryBuilder, HttpContent cnt, Nullable`1 serverTimeout, OperationContext ctx)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteAsyncInternal[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext, CancellationToken token)
at Microsoft.WindowsAzure.Storage.Table.TableQuery`1.<>c__DisplayClass20_0.<<ExecuteQuerySegmentedAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.<>c__DisplayClass27_0.<<ReadTableEntriesAndEtagsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.AsyncExecutorWithRetries.ExecuteWithRetriesHelper[T](Func`2 function, Int32 callCounter, Int32 maxNumSuccessTries, Int32 maxNumErrorTries, TimeSpan maxExecutionTime, DateTime startExecutionTime, Func`3 retryValueFilter, Func`3 retryExceptionFilter, IBackoffProvider onSuccessBackOff, IBackoffProvider onErrorBackOff)
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
--- End of inner exception stack trace ---
at Orleans.Reminders.AzureStorage.AzureTableDataManager`1.ReadTableEntriesAndEtagsAsync(String filter)
at Orleans.Runtime.ReminderService.RemindersTableManager.FindReminderEntries(UInt32 begin, UInt32 end)
at Orleans.Runtime.ReminderService.AzureBasedReminderTable.ReadRows(UInt32 begin, UInt32 end)
at Orleans.Runtime.ReminderService.LocalReminderService.ReadTableAndStartTimers(IRingRange range, Int32 rangeSerialNumberCopy)
2. For membership
2018-10-25T15:11:57.0440856Z [883] ERROR production barista-api-deployment-558b6b5bbd-2l669 10.245.7.16 Orleans.AzureUtils.OrleansSiloInstanceManager {log4net:UserName=NOT AVAILABLE, log4net:Identity=NOT AVAILABLE, EventID=100331, log4net:HostName=barista-api-deployment-558b6b5bbd-2l669} - Error searching for active gateway silos for deployment mydeployment-orleans-silo
System.TimeoutException: WithTimeout has timed out after 00:00:03
at Orleans.OrleansTaskExtentions.<WithTimeout>d__17`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.AzureUtils.OrleansSiloInstanceManager.<FindAllGatewaySilos>d__21.MoveNext()
There's probably some correlation between TableStorageUpdateConditionNotSatisfiedException (see below, bars are counts of errors in 30 minutes)

I can confidently say that we've been seeing exceptions above since Orleans 1.5.
I also noticed something that may or may not be related. In the last couple of days, the stopwatch code in my initial message was logging times like 1000-2000 seconds for writing/reading state. That correlated with the below health warnings displayed in Azure portal for that Storage Account:

Also server latencies for the storage account were maxing at 5-8 seconds. This one is probably unrelated and something was wrong with the storage service itself. We used to have dedicated storage accounts for reminders, pubsub and membership+grainstate and recently merged all into one for simplicity. Just in case we reverted that back now, but our request rates with storage were nowhere near the limit of 20k requests per second - that's how many we send in ~6h.
So I cannot map that issue with what I'm seeing exactly, but I can imagine how thread safety issues could cause both issues.
Is it likely to help if instead of sharing an instance of CloudTable here https://github.com/dotnet/orleans/blob/master/src/Azure/Shared/Storage/AzureTableDataManager.cs#L52 we create one per request?
Ok, it seems to me I'm dealing with more than one issue. The fix proposed in #5003 should eliminate some of my exceptions - I'm going to use a custom build of WindowsAzure.Storage.
I think it's still worthwhile fixing the threadsafety issue with something like this https://github.com/dotnet/orleans/commit/ef65cb9ec1a2fda68e7d654d5823953fd373f602 @sergeybykov should I submit a PR?
Also, what is the reason for using WindowsAzureStorageVersion at version 8.2.1? There have been numerous bug fixes since that version. I'm going to try upgrading it. If that's successful, I'm going to send a PR unless there are reasons against it.
should I submit a PR?
PRs are always welcome!
Also, what is the reason for using WindowsAzureStorageVersion at version 8.2.1? There have been numerous bug fixes since that version.
The general principle is that we do not want to force people to upgrade to a newer version of a dependency library before they are ready, unless there's a strong reason for that (major bug fixes or new features that we depend on).
A quick update. We deployed the fix discussed in https://github.com/dotnet/orleans/issues/5003 and have run it for a few months now. It did help with other exceptions, but not the TableStorageUpdateConditionNotSatisfiedException.
The next thing I'm going to try is the change I made here https://github.com/dotnet/orleans/commit/ef65cb9ec1a2fda68e7d654d5823953fd373f602, which is a bit of a blind shot as I've not found a strong evidence that sharing of client instances is causing the problem. I'll submit that as PR if the change does anything.
Let us know what happens after that! We appreciate your experiments here.
Hi,
We are also seeing this exception:
Failed to read Azure storage table OrleansSiloInstances: An item with the same key has already been added. Key: timeout Microsoft.WindowsAzure.Storage.StorageException: An item with the same key has already been added. Key: timeout ---> System.ArgumentException: An item with the same key has already been added. Key: timeout
And also around once per hour, we are seeing:
Slow access to Azure Table "OrleansSiloInstances" for "ReadTableEntriesAndEtags", which took "00:02:03.2541586".
Client side we have some of these:
Exception occurred during RefreshSnapshotLiveGateways_TimerCallback -> listProvider.GetGateways() System.TimeoutException: WithTimeout has timed out after 00:00:03 at Orleans.OrleansTaskExtentions.WithTimeout[T](Task`1 taskToComplete, TimeSpan timeSpan, String exceptionMessage) at Orleans.AzureUtils.OrleansSiloInstanceManager.FindAllGatewaySilos() at Orleans.AzureUtils.OrleansSiloInstanceManager.FindAllGatewayProxyEndpoints() at Orleans.Messaging.GatewayManager.RefreshSnapshotLiveGateways_TimerCallback(Object context)
Is this all related to the same issue? Basically, my interpretation is that this is caused by threading bugs in the library WindowsAzureStorage from two years ago.
what's the plan moving forward regarding the Azure Table SDK now that it's moving to the Cosmos team? is it scheduled by the Orleans team?
Edited: we are using Orleans 2.3.2 and deploying as a containerized app into a Kubernetes cluster.
Hi. We too are seeing the reminder exceptions, running the newest versions of Orleans (3.0.1), also in a container in a Kubernetes cluster.
Failed to read Azure storage table OrleansSiloInstances: An item with the same key has already been added. Key: timeout Microsoft.WindowsAzure.Storage.StorageException: An item with the same key has already been added. Key: timeout ---> System.ArgumentException: An item with the same key has already been added. Key: timeout
I see a similar problem on my Kubernetes cluster.
We are not seeing this issue anymore in our solution.
Did upgrading Orleans or AKS help you @rvplauborg ?
I think it must have been the upgrade of Orleans, but I am not totally sure, sorry!
Closing this issue, it should have been fixed with an upgrade of the Azure SDK