Skip to content

Commit 21770f0

Browse files
bluewwshahabhijeet
authored andcommitted
Fix the storage cmdlets that will hang when called from event (#3299)
1 parent c89f9dc commit 21770f0

30 files changed

+69
-69
lines changed

src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageBlob.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ internal async Task<CloudBlobContainer> GetCloudBlobContainerByName(IStorageBlob
146146
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
147147

148148
if (!skipCheckExists && container.ServiceClient.Credentials.IsSharedKey
149-
&& !await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
149+
&& !await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false))
150150
{
151151
throw new ArgumentException(String.Format(Resources.ContainerNotFound, containerName));
152152
}
@@ -170,7 +170,7 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
170170

171171
if (String.IsNullOrEmpty(blobName) || WildcardPattern.ContainsWildcardCharacters(blobName))
172172
{
173-
container = await GetCloudBlobContainerByName(localChannel, containerName);
173+
container = await GetCloudBlobContainerByName(localChannel, containerName).ConfigureAwait(false);
174174
prefix = NameUtil.GetNonWildcardPrefix(blobName);
175175
WildcardOptions options = WildcardOptions.IgnoreCase | WildcardOptions.Compiled;
176176
WildcardPattern wildcard = null;
@@ -181,18 +181,18 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
181181
}
182182

183183
Func<CloudBlob, bool> blobFilter = (blob) => wildcard == null || wildcard.IsMatch(blob.Name);
184-
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter);
184+
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter).ConfigureAwait(false);
185185
}
186186
else
187187
{
188-
container = await GetCloudBlobContainerByName(localChannel, containerName, true);
188+
container = await GetCloudBlobContainerByName(localChannel, containerName, true).ConfigureAwait(false);
189189

190190
if (!NameUtil.IsValidBlobName(blobName))
191191
{
192192
throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName));
193193
}
194194

195-
CloudBlob blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
195+
CloudBlob blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
196196

197197
if (null == blob)
198198
{
@@ -213,7 +213,7 @@ internal async Task ListBlobsByName(long taskId, IStorageBlobManagement localCha
213213
/// <returns>An enumerable collection of IListBlobItem</returns>
214214
internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localChannel, string containerName, string prefix, Func<CloudBlob, bool> blobFilter = null)
215215
{
216-
CloudBlobContainer container = await GetCloudBlobContainerByName(localChannel, containerName);
216+
CloudBlobContainer container = await GetCloudBlobContainerByName(localChannel, containerName).ConfigureAwait(false);
217217

218218
BlobRequestOptions requestOptions = RequestOptions;
219219
bool useFlatBlobListing = true;
@@ -230,7 +230,7 @@ internal async Task ListBlobsByPrefix(long taskId, IStorageBlobManagement localC
230230
requestCount = Math.Min(listCount, MaxListCount);
231231
realListCount = 0;
232232
BlobResultSegment blobResult = await localChannel.ListBlobsSegmentedAsync(container, prefix, useFlatBlobListing,
233-
details, requestCount, continuationToken, requestOptions, OperationContext, CmdletCancellationToken);
233+
details, requestCount, continuationToken, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
234234

235235
foreach (IListBlobItem blobItem in blobResult.Results)
236236
{

src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageBlobContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ await DataMovementTransferHelper.DoTransfer(() =>
144144
this.CmdletCancellationToken);
145145
},
146146
data.Record,
147-
this.OutputStream);
147+
this.OutputStream).ConfigureAwait(false);
148148

149149
this.WriteCloudBlobObject(data.TaskId, data.Channel, blob);
150150
}

src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageBlobCopyState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ protected async Task MonitorBlobCopyStatusAsync(long taskId)
273273
long internalTaskId = monitorRequest.Item1;
274274
CloudBlob blob = monitorRequest.Item2;
275275
//Just use the last blob management channel since the following operation is context insensitive
276-
await Channel.FetchBlobAttributesAsync(blob, accessCondition, requestOptions, context, CmdletCancellationToken);
276+
await Channel.FetchBlobAttributesAsync(blob, accessCondition, requestOptions, context, CmdletCancellationToken).ConfigureAwait(false);
277277
bool taskDone = false;
278278

279279
if (blob.CopyState == null)

src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ internal async Task GetContainerPermission(long taskId, IStorageBlobManagement l
228228
try
229229
{
230230
permissions = await localChannel.GetContainerPermissionsAsync(container, accessCondition,
231-
requestOptions, OperationContext, CmdletCancellationToken);
231+
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
232232
}
233233
catch (StorageException e)
234234
{

src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageContainerStoredAccessPolicy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public GetAzureStorageContainerStoredAccessPolicyCommand(IStorageBlobManagement
6161

6262
internal async Task GetAzureContainerStoredAccessPolicyAsync(long taskId, IStorageBlobManagement localChannel, string containerName, string policyName)
6363
{
64-
SharedAccessBlobPolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, containerName, policyName);
64+
SharedAccessBlobPolicies shareAccessPolicies = await GetPoliciesAsync(localChannel, containerName, policyName).ConfigureAwait(false);
6565

6666
if (!String.IsNullOrEmpty(policyName))
6767
{
@@ -86,7 +86,7 @@ internal async Task GetAzureContainerStoredAccessPolicyAsync(long taskId, IStora
8686
internal async Task<SharedAccessBlobPolicies> GetPoliciesAsync(IStorageBlobManagement localChannel, string containerName, string policyName)
8787
{
8888
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
89-
BlobContainerPermissions blobContainerPermissions = await localChannel.GetContainerPermissionsAsync(container, null, null, null, CmdletCancellationToken);
89+
BlobContainerPermissions blobContainerPermissions = await localChannel.GetContainerPermissionsAsync(container, null, null, null, CmdletCancellationToken).ConfigureAwait(false);
9090
return blobContainerPermissions.SharedAccessPolicies;
9191
}
9292

src/Storage/Commands.Storage/Blob/Cmdlet/NewAzureStorageContainer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ internal async Task CreateAzureContainer(long taskId, IStorageBlobManagement loc
8282

8383
permissions.PublicAccess = accesslevel;
8484

85-
bool created = await localChannel.CreateContainerIfNotExistsAsync(container, permissions.PublicAccess, requestOptions, OperationContext, CmdletCancellationToken);
85+
bool created = await localChannel.CreateContainerIfNotExistsAsync(container, permissions.PublicAccess, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
8686

8787
if (!created)
8888
{

src/Storage/Commands.Storage/Blob/Cmdlet/RemoveAzureStorageBlob.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
149149

150150
try
151151
{
152-
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption);
152+
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption).ConfigureAwait(false);
153153
retryDeleteSnapshot = false;
154154
}
155155
catch (StorageException e)
@@ -169,10 +169,10 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
169169
{
170170
string message = string.Format(Resources.ConfirmRemoveBlobWithSnapshot, blob.Name, blob.Container.Name);
171171

172-
if (await OutputStream.ConfirmAsync(message))
172+
if (await OutputStream.ConfirmAsync(message).ConfigureAwait(false))
173173
{
174174
deleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;
175-
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption);
175+
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption).ConfigureAwait(false);
176176
}
177177
else
178178
{
@@ -188,7 +188,7 @@ internal async Task DeleteCloudAsync(long taskId, IStorageBlobManagement localCh
188188
BlobRequestOptions requestOptions = null;
189189

190190
await localChannel.DeleteCloudBlobAsync(blob, deleteSnapshotsOption, accessCondition,
191-
requestOptions, OperationContext, CmdletCancellationToken);
191+
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
192192

193193
string result = String.Format(Resources.RemoveBlobSuccessfully, blob.Name, blob.Container.Name);
194194

@@ -222,7 +222,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
222222
try
223223
{
224224
blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition,
225-
requestOptions, OperationContext, CmdletCancellationToken);
225+
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
226226
}
227227
catch (InvalidOperationException)
228228
{
@@ -240,7 +240,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
240240
blob = container.GetBlockBlobReference(blobName);
241241
}
242242

243-
await RemoveAzureBlob(taskId, localChannel, blob, true);
243+
await RemoveAzureBlob(taskId, localChannel, blob, true).ConfigureAwait(false);
244244
}
245245

246246
/// <summary>
@@ -252,7 +252,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
252252
internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName)
253253
{
254254
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
255-
await RemoveAzureBlob(taskId, localChannel, container, blobName);
255+
await RemoveAzureBlob(taskId, localChannel, container, blobName).ConfigureAwait(false);
256256
}
257257

258258
/// <summary>

src/Storage/Commands.Storage/Blob/Cmdlet/RemoveAzureStorageContainer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ internal async Task RemoveAzureContainer(long taskId, IStorageBlobManagement loc
8282

8383
CloudBlobContainer container = localChannel.GetContainerReference(name);
8484

85-
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
85+
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false))
8686
{
8787
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
8888
}
@@ -92,7 +92,7 @@ internal async Task RemoveAzureContainer(long taskId, IStorageBlobManagement loc
9292

9393
if (force || ContainerIsEmpty(container) || OutputStream.ConfirmAsync(String.Format("Remove container and all content in it: {0}", name)).Result)
9494
{
95-
await localChannel.DeleteContainerAsync(container, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
95+
await localChannel.DeleteContainerAsync(container, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
9696
result = String.Format(Resources.RemoveContainerSuccessfully, name);
9797
removed = true;
9898
}

src/Storage/Commands.Storage/Blob/Cmdlet/SetAzureStorageBlobContent.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ await DataMovementTransferHelper.DoTransfer(() =>
203203
this.CmdletCancellationToken);
204204
},
205205
data.Record,
206-
this.OutputStream);
206+
this.OutputStream).ConfigureAwait(false);
207207

208208
if (this.BlobProperties != null || this.BlobMetadata != null)
209209
{
210210
await TaskEx.WhenAll(
211211
this.SetBlobProperties(localChannel, blob, this.BlobProperties),
212-
this.SetBlobMeta(localChannel, blob, this.BlobMetadata));
212+
this.SetBlobMeta(localChannel, blob, this.BlobMetadata)).ConfigureAwait(false);
213213
}
214214

215215
try
@@ -219,7 +219,7 @@ await localChannel.FetchBlobAttributesAsync(
219219
AccessCondition.GenerateEmptyCondition(),
220220
this.RequestOptions,
221221
this.OperationContext,
222-
this.CmdletCancellationToken);
222+
this.CmdletCancellationToken).ConfigureAwait(false);
223223
}
224224
catch (StorageException e)
225225
{
@@ -370,7 +370,7 @@ private async Task SetBlobProperties(IStorageBlobManagement localChannel, Storag
370370
AccessCondition accessCondition = null;
371371
StorageBlob.BlobRequestOptions requestOptions = RequestOptions;
372372

373-
await Channel.SetBlobPropertiesAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
373+
await Channel.SetBlobPropertiesAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
374374
}
375375

376376
/// <summary>
@@ -403,7 +403,7 @@ private async Task SetBlobMeta(IStorageBlobManagement localChannel, StorageBlob.
403403
AccessCondition accessCondition = null;
404404
StorageBlob.BlobRequestOptions requestOptions = RequestOptions;
405405

406-
await Channel.SetBlobMetadataAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
406+
await Channel.SetBlobMetadataAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
407407
}
408408

409409
/// <summary>

src/Storage/Commands.Storage/Blob/Cmdlet/SetAzureStorageContainerAcl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ internal async Task SetContainerAcl(long taskId, IStorageBlobManagement localCha
8787

8888
CloudBlobContainer container = localChannel.GetContainerReference(name);
8989

90-
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
90+
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false))
9191
{
9292
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
9393
}
9494

95-
await localChannel.SetContainerPermissionsAsync(container, permissions, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
95+
await localChannel.SetContainerPermissionsAsync(container, permissions, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
9696

9797
if (PassThru)
9898
{

src/Storage/Commands.Storage/Blob/Cmdlet/StartAzureStorageBlobCopy.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha
492492
{
493493
try
494494
{
495-
await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob);
495+
await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false);
496496
}
497497
catch (StorageException ex)
498498
{
@@ -516,7 +516,7 @@ private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChan
516516
bool destExist = true;
517517
try
518518
{
519-
await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
519+
await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
520520
}
521521
catch (StorageException ex)
522522
{
@@ -532,15 +532,15 @@ private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChan
532532

533533
if (!destExist || this.ConfirmOverwrite(srcUri.AbsoluteUri.ToString(), destBlob.Uri.ToString()))
534534
{
535-
string copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
535+
string copyId = await destChannel.StartCopyAsync(destBlob, srcUri, null, null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
536536
this.OutputStream.WriteVerbose(taskId, String.Format(Resources.CopyDestinationBlobPending, destBlob.Name, destBlob.Container.Name, copyId));
537537
this.WriteCloudBlobObject(taskId, destChannel, destBlob);
538538
}
539539
}
540540

541541
private async Task StartCopyFromFile(long taskId, IStorageBlobManagement destChannel, CloudFile srcFile, CloudBlockBlob destBlob)
542542
{
543-
await this.StartCopyFromUri(taskId, destChannel, srcFile.GenerateUriWithCredentials(), destBlob);
543+
await this.StartCopyFromUri(taskId, destChannel, srcFile.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false);
544544
}
545545

546546
private CloudBlob GetDestBlob(IStorageBlobManagement destChannel, string destContainerName, string destBlobName, BlobType blobType)
@@ -583,7 +583,7 @@ private async Task StartCopyAsync(long taskId, IStorageBlobManagement destChanne
583583
NameUtil.ValidateContainerName(destBlob.Container.Name);
584584
NameUtil.ValidateBlobName(destBlob.Name);
585585

586-
await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob);
586+
await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob).ConfigureAwait(false);
587587
}
588588

589589
/// <summary>

0 commit comments

Comments
 (0)