File tree Expand file tree Collapse file tree
CoreHelpers.WindowsAzure.Storage.Table/Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -49,8 +49,34 @@ public static async Task<Response<IReadOnlyList<Response>>> SubmitTransactionWit
4949 // check the exception
5050 if ( allowAutoCreate && ex . ErrorCode . Equals ( "TableNotFound" ) )
5151 {
52- // try to create the table
53- await tc . CreateAsync ( ) ;
52+
53+ // This is a double check pattern to ensure that two independent processes
54+ // who are trying to create the table in parallel do not end up in an unhandled
55+ // situation.
56+ try
57+ {
58+ // try to create the table
59+ await tc . CreateAsync ( ) ;
60+ }
61+ catch ( TableTransactionFailedException doubleCheckEx )
62+ {
63+ // check if we have an errorCode if not the system throws the exception
64+ // to the caller
65+ if ( String . IsNullOrEmpty ( doubleCheckEx . ErrorCode ) )
66+ {
67+ ExceptionDispatchInfo . Capture ( ex ) . Throw ( ) ;
68+ return null ;
69+ }
70+
71+ // Every error except the TableAlreadyExists is thrown to the caller but
72+ // in the case the system is trying to create the table in parallel we
73+ // ignore the error and execute the transaction!
74+ if ( ! doubleCheckEx . ErrorCode . Equals ( "TableAlreadyExists" ) )
75+ {
76+ ExceptionDispatchInfo . Capture ( ex ) . Throw ( ) ;
77+ return null ;
78+ }
79+ }
5480
5581 // retry
5682 return await tc . SubmitTransactionAsync ( transactionActions , cancellationToken ) ;
You can’t perform that action at this time.
0 commit comments