Skip to content

Storage: fix the cmdlets hang in event issue #3299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/Storage/Commands.Storage/Blob/Cmdlet/GetAzureStorageBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ internal async Task<CloudBlobContainer> GetCloudBlobContainerByName(IStorageBlob
CloudBlobContainer container = localChannel.GetContainerReference(containerName);

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

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

Func<CloudBlob, bool> blobFilter = (blob) => wildcard == null || wildcard.IsMatch(blob.Name);
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter);
await ListBlobsByPrefix(taskId, localChannel, containerName, prefix, blobFilter).ConfigureAwait(false);
}
else
{
container = await GetCloudBlobContainerByName(localChannel, containerName, true);
container = await GetCloudBlobContainerByName(localChannel, containerName, true).ConfigureAwait(false);

if (!NameUtil.IsValidBlobName(blobName))
{
throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName));
}

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

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

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

foreach (IListBlobItem blobItem in blobResult.Results)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ await DataMovementTransferHelper.DoTransfer(() =>
this.CmdletCancellationToken);
},
data.Record,
this.OutputStream);
this.OutputStream).ConfigureAwait(false);

this.WriteCloudBlobObject(data.TaskId, data.Channel, blob);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ protected async Task MonitorBlobCopyStatusAsync(long taskId)
long internalTaskId = monitorRequest.Item1;
CloudBlob blob = monitorRequest.Item2;
//Just use the last blob management channel since the following operation is context insensitive
await Channel.FetchBlobAttributesAsync(blob, accessCondition, requestOptions, context, CmdletCancellationToken);
await Channel.FetchBlobAttributesAsync(blob, accessCondition, requestOptions, context, CmdletCancellationToken).ConfigureAwait(false);
bool taskDone = false;

if (blob.CopyState == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ internal async Task GetContainerPermission(long taskId, IStorageBlobManagement l
try
{
permissions = await localChannel.GetContainerPermissionsAsync(container, accessCondition,
requestOptions, OperationContext, CmdletCancellationToken);
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
}
catch (StorageException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public GetAzureStorageContainerStoredAccessPolicyCommand(IStorageBlobManagement

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal async Task CreateAzureContainer(long taskId, IStorageBlobManagement loc

permissions.PublicAccess = accesslevel;

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

if (!created)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha

try
{
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption);
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption).ConfigureAwait(false);
retryDeleteSnapshot = false;
}
catch (StorageException e)
Expand All @@ -169,10 +169,10 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
{
string message = string.Format(Resources.ConfirmRemoveBlobWithSnapshot, blob.Name, blob.Container.Name);

if (await OutputStream.ConfirmAsync(message))
if (await OutputStream.ConfirmAsync(message).ConfigureAwait(false))
{
deleteSnapshotsOption = DeleteSnapshotsOption.IncludeSnapshots;
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption);
await DeleteCloudAsync(taskId, localChannel, blob, deleteSnapshotsOption).ConfigureAwait(false);
}
else
{
Expand All @@ -188,7 +188,7 @@ internal async Task DeleteCloudAsync(long taskId, IStorageBlobManagement localCh
BlobRequestOptions requestOptions = null;

await localChannel.DeleteCloudBlobAsync(blob, deleteSnapshotsOption, accessCondition,
requestOptions, OperationContext, CmdletCancellationToken);
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);

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

Expand Down Expand Up @@ -222,7 +222,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
try
{
blob = await localChannel.GetBlobReferenceFromServerAsync(container, blobName, accessCondition,
requestOptions, OperationContext, CmdletCancellationToken);
requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
}
catch (InvalidOperationException)
{
Expand All @@ -240,7 +240,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
blob = container.GetBlockBlobReference(blobName);
}

await RemoveAzureBlob(taskId, localChannel, blob, true);
await RemoveAzureBlob(taskId, localChannel, blob, true).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -252,7 +252,7 @@ internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localCha
internal async Task RemoveAzureBlob(long taskId, IStorageBlobManagement localChannel, string containerName, string blobName)
{
CloudBlobContainer container = localChannel.GetContainerReference(containerName);
await RemoveAzureBlob(taskId, localChannel, container, blobName);
await RemoveAzureBlob(taskId, localChannel, container, blobName).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ internal async Task RemoveAzureContainer(long taskId, IStorageBlobManagement loc

CloudBlobContainer container = localChannel.GetContainerReference(name);

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

if (force || ContainerIsEmpty(container) || OutputStream.ConfirmAsync(String.Format("Remove container and all content in it: {0}", name)).Result)
{
await localChannel.DeleteContainerAsync(container, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
await localChannel.DeleteContainerAsync(container, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
result = String.Format(Resources.RemoveContainerSuccessfully, name);
removed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,13 @@ await DataMovementTransferHelper.DoTransfer(() =>
this.CmdletCancellationToken);
},
data.Record,
this.OutputStream);
this.OutputStream).ConfigureAwait(false);

if (this.BlobProperties != null || this.BlobMetadata != null)
{
await TaskEx.WhenAll(
this.SetBlobProperties(localChannel, blob, this.BlobProperties),
this.SetBlobMeta(localChannel, blob, this.BlobMetadata));
this.SetBlobMeta(localChannel, blob, this.BlobMetadata)).ConfigureAwait(false);
}

try
Expand All @@ -219,7 +219,7 @@ await localChannel.FetchBlobAttributesAsync(
AccessCondition.GenerateEmptyCondition(),
this.RequestOptions,
this.OperationContext,
this.CmdletCancellationToken);
this.CmdletCancellationToken).ConfigureAwait(false);
}
catch (StorageException e)
{
Expand Down Expand Up @@ -370,7 +370,7 @@ private async Task SetBlobProperties(IStorageBlobManagement localChannel, Storag
AccessCondition accessCondition = null;
StorageBlob.BlobRequestOptions requestOptions = RequestOptions;

await Channel.SetBlobPropertiesAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
await Channel.SetBlobPropertiesAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down Expand Up @@ -403,7 +403,7 @@ private async Task SetBlobMeta(IStorageBlobManagement localChannel, StorageBlob.
AccessCondition accessCondition = null;
StorageBlob.BlobRequestOptions requestOptions = RequestOptions;

await Channel.SetBlobMetadataAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken);
await Channel.SetBlobMetadataAsync(blob, accessCondition, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ internal async Task SetContainerAcl(long taskId, IStorageBlobManagement localCha

CloudBlobContainer container = localChannel.GetContainerReference(name);

if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken))
if (!await localChannel.DoesContainerExistAsync(container, requestOptions, OperationContext, CmdletCancellationToken).ConfigureAwait(false))
{
throw new ResourceNotFoundException(String.Format(Resources.ContainerNotFound, name));
}

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

if (PassThru)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ private async Task StartCopyFromBlob(long taskId, IStorageBlobManagement destCha
{
try
{
await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob);
await StartCopyFromUri(taskId, destChannel, srcBlob.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false);
}
catch (StorageException ex)
{
Expand All @@ -516,7 +516,7 @@ private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChan
bool destExist = true;
try
{
await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken);
await destBlob.FetchAttributesAsync(null, this.RequestOptions, this.OperationContext, this.CmdletCancellationToken).ConfigureAwait(false);
}
catch (StorageException ex)
{
Expand All @@ -532,15 +532,15 @@ private async Task StartCopyFromUri(long taskId, IStorageBlobManagement destChan

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

private async Task StartCopyFromFile(long taskId, IStorageBlobManagement destChannel, CloudFile srcFile, CloudBlockBlob destBlob)
{
await this.StartCopyFromUri(taskId, destChannel, srcFile.GenerateUriWithCredentials(), destBlob);
await this.StartCopyFromUri(taskId, destChannel, srcFile.GenerateUriWithCredentials(), destBlob).ConfigureAwait(false);
}

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

await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob);
await this.StartCopyFromBlob(taskId, destChannel, sourceBlob, destBlob).ConfigureAwait(false);
}

/// <summary>
Expand Down
Loading