azure-sdk-for-net: BlobLeaseClient.GetBlobClient returns "The value for one of the HTTP headers is not in the correct format" exception
Describe the bug When trying to aquire a lease on a blob I get the an exception.
Expected behavior I should be able to acquire a lease on this blob.
Actual behavior (include Exception or Stack Trace)
The value for one of the HTTP headers is not in the correct format.
RequestId:<guid>
Time:2020-09-30T10:28:47.8781946Z
Status: 400 (The value for one of the HTTP headers is not in the correct format.)
ErrorCode: InvalidHeaderValue
Headers:
Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id: <guid>
x-ms-client-request-id: <guid>
x-ms-version: 2019-12-12
x-ms-error-code: InvalidHeaderValue
Date: Wed, 30 Sep 2020 10:28:47 GMT
Content-Length: 328
Content-Type: application/xml
To Reproduce
BlockBlobClient blockBlobClient = new BlockBlobClient(
"connectionstring",
"containername",
"blob");
BlobLeaseClient blc = blockBlobClient.GetBlobLeaseClient();
//exception here
BlobLease bl = await blc.AcquireAsync(new TimeSpan(0, 0, 10));
Environment:
- Azure.Storage.Blobs, Version=12.6.0.0
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (9 by maintainers)
Client-side validation can result in really painful forward compatibility problems.
To better illustrate, let’s pretend we added client-side validation for an operation like Set Blob Tags. There’s a maximum of 10 tags so why not enforce that before we send an expensive request across the network? It seems safe.
It’s harder to imagine something like this happening with blob leases, but I could see someone getting the current lease duration via
GetProperties
and callingLeaseClient.Break
with it (i.e., I’ll let you finish one lease, but not renew it).If we can’t make the error messages better with #14469, then the most we should do is post facto client-side validation where we catch the error, determine it’s because the lease was out of range, and then wrap it in an exception that’s more helpful to customers.
Hi,
“A non-infinite lease can be between 15 and 60 seconds”. https://docs.microsoft.com/en-us/rest/api/storageservices/lease-blob (see x-ms-lease-duration)
That’s why the stackoverflow link you used worked cause it was 30 seconds while the snippet you provided was 10 seconds. So the error code you got back from the service “InvalidHeaderValue” is correct.
@tg-msft could you jump in with why we allow users to specify values that are not valid to the service. I believe there’s a SDK guideline (something like that) with allowing the service to handle error messages.
With creating more user friendly error messages, we actually have an issue already open for that. See https://github.com/Azure/azure-sdk-for-net/issues/14469
The response has a payload that contain information about which header is invalid. We should either expose it or add client side validation.
So why does the
AcquireAsync
allow me to specify a value < 15 seconds?! I still think this is a bug. I’d say:AcquireAsync
should parse these inputsYes @seanmcc-msft please could you re-open this ticket
I did actually get something working https://stackoverflow.com/a/64136116/542251
But the above looks to me like it should work. So why doesn’t it?
I’d suggest at the very least that the error message is confusing/vague.