banco-alimentar / alimentestaideia.pt

Site doações alimente esta ideia
http://alimentestaideia.pt
Other
10 stars 0 forks source link

Unhandled exception BlobAlreadyExists while getting invoice in prod #764

Open tiagonmas opened 9 months ago

tiagonmas commented 9 months ago

I was on CheckPaymentStatus, after the payment was confirmed I received this error in production. Could be that the invoice was generated at the same time by the background service (so it could send the invoice by email) and then when it tried to generate the invoice again for me, it gave this error

Azure.RequestFailedException: The specified blob already exists.
RequestId:ebf131f1-f01e-006f-086d-1879f5000000
Time:2023-11-16T09:18:17.2988243Z
Status: 409 (The specified blob already exists.)
ErrorCode: BlobAlreadyExists

Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>BlobAlreadyExists</Code><Message>The specified blob already exists.
RequestId:ebf131f1-f01e-006f-086d-1879f5000000
Time:2023-11-16T09:18:17.2988243Z</Message></Error>

Headers:
Server: Windows-Azure-Blob/1.0 Microsoft-HTTPAPI/2.0
x-ms-request-id: ebf131f1-f01e-006f-086d-1879f5000000
x-ms-client-request-id: e05d2ea9-c616-4687-a296-94a0c78458b6
x-ms-version: 2023-08-03
x-ms-error-code: BlobAlreadyExists
Date: Thu, 16 Nov 2023 09:18:16 GMT
Content-Length: 220
Content-Type: application/xml

   at Azure.Storage.Blobs.BlockBlobRestClient.UploadAsync(Int64 contentLength, Stream body, Nullable`1 timeout, Byte[] transactionalContentMD5, String blobContentType, String blobContentEncoding, String blobContentLanguage, Byte[] blobContentMD5, String blobCacheControl, IDictionary`2 metadata, String leaseId, String blobContentDisposition, String encryptionKey, String encryptionKeySha256, Nullable`1 encryptionAlgorithm, String encryptionScope, Nullable`1 tier, Nullable`1 ifModifiedSince, Nullable`1 ifUnmodifiedSince, String ifMatch, String ifNoneMatch, String ifTags, String blobTagsString, Nullable`1 immutabilityPolicyExpiry, Nullable`1 immutabilityPolicyMode, Nullable`1 legalHold, Byte[] transactionalContentCrc64, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.Specialized.BlockBlobClient.UploadInternal(Stream content, BlobHttpHeaders blobHttpHeaders, IDictionary`2 metadata, IDictionary`2 tags, BlobRequestConditions conditions, Nullable`1 accessTier, BlobImmutabilityPolicy immutabilityPolicy, Nullable`1 legalHold, IProgress`1 progressHandler, UploadTransferValidationOptions transferValidationOverride, String operationName, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.Specialized.BlockBlobClient.<>c__DisplayClass65_0.<<GetPartitionedUploaderBehaviors>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Azure.Storage.PartitionedUploader`2.UploadInternal(Stream content, Nullable`1 expectedContentLength, TServiceSpecificData args, IProgress`1 progressHandler, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.BlobClient.StagedUploadInternal(Stream content, BlobUploadOptions options, Boolean async, CancellationToken cancellationToken)
   at Azure.Storage.Blobs.BlobClient.UploadAsync(Stream content)
   at BancoAlimentar.AlimentaEstaIdeia.Web.Areas.Identity.Pages.Account.Manage.GenerateInvoiceModel.GenerateInvoiceInternalAsync(String publicDonationId, Tenant tenant, Boolean generateInvoice) in D:\a\1\s\BancoAlimentar.AlimentaEstaIdeia.Web\Areas\Identity\Pages\Account\Manage\GenerateInvoice.cshtml.cs:line 254
   at BancoAlimentar.AlimentaEstaIdeia.Web.Areas.Identity.Pages.Account.Manage.GenerateInvoiceModel.OnGetAsync(String publicDonationId) in D:\a\1\s\BancoAlimentar.AlimentaEstaIdeia.Web\Areas\Identity\Pages\Account\Manage\GenerateInvoice.cshtml.cs:line 102
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.GenericTaskHandlerMethod.Convert[T](Object taskAsObject)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.ExecutorFactory.GenericTaskHandlerMethod.Execute(Object receiver, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeHandlerMethodAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeNextPageFilterAsync()
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Rethrow(PageHandlerExecutedContext context)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at BancoAlimentar.AlimentaEstaIdeia.Sas.Core.Middleware.DoarTenantMiddleware.Invoke(HttpContext context, ITenantProvider tenantProvider, IInfrastructureUnitOfWork unitOfWork, IKeyVaultConfigurationManager keyVaultConfigurationManager, IWebHostEnvironment webHostEnvironment, IConfiguration configuration) in D:\a\1\s\BancoAlimentar.AlimentaEstaIdeia.Sas.Core\Middleware\DoarTenantMiddleware.cs:line 129
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)
guerrerotook commented 9 months ago

@tiagonmas I added a try catch in case this exception happens and it's the same message. If not then I will rethrow the exception.

If the file is already on the server we can assume that the email background service already generated the pdf so there is no need to upload that again.