Skip to content
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

Removing content item with enabled Amazon S3 storage provider causes exepton in logs #15169

Closed
AndreySurkov opened this issue Jan 25, 2024 · 1 comment · Fixed by #15239
Closed
Labels

Comments

@AndreySurkov
Copy link
Contributor

Describe the bug

I have setup of OrchardCore with enabled Amazon S3 storage provider. when I delete any content item in system I see an error related to S3 call in logs. This error does not affect any functionality but looks unnecessary.

OrchardCore.Media module has AttachedMediaFieldContentHandler that reacts on content deletion and tries to delete related media files if exists. Call passed through AttachedMediaFieldFileService > DefaultMediaFileStore > AwsFileStorage.TryDeleteDirectoryAsync.
TryDeleteDirectoryAsync method first tries to retrieve any objects related to specific path, and then makes call to DeleteObjectsAsync to remove them. But in case if there are no objects exist for removal, DeleteObjectsAsync call still executes (with empty list of objects to delete) and results in an error.

To Reproduce

Steps to reproduce the behavior:

  1. Run OC on the latest main commit
  2. Set up the site with any recipe
  3. Enable the Amazon Media Storage feature and configure it
  4. Create any content item.
  5. Delete item created on step 4

Expected behavior

The are no errors in logs.

Actual behavior

I see error in logs:

"IContentHandler" thrown from "OrchardCore.Media.Handlers.AttachedMediaFieldContentHandler" by 
"AmazonS3Exception"",

Amazon.S3.AmazonS3Exception: The XML you provided was not well-formed or did not validate against our published schema
Amazon.Runtime.Internal.HttpErrorResponseException: Exception of type 'Amazon.Runtime.Internal.HttpErrorResponseException' was thrown.
   at Amazon.Runtime.HttpWebRequestMessage.GetResponseAsync(CancellationToken cancellationToken)
   at Amazon.Runtime.Internal.HttpHandler`1.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RedirectHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Unmarshaller.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.S3.Internal.AmazonS3ResponseHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   --- End of inner exception stack trace --
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionStream(IRequestContext requestContext, IWebResponseData httpErrorResponse, HttpErrorResponseException exception, Stream responseStream)
   at Amazon.Runtime.Internal.HttpErrorResponseExceptionHandler.HandleExceptionAsync(IExecutionContext executionContext, HttpErrorResponseException exception)
   at Amazon.Runtime.Internal.ExceptionHandler`1.HandleAsync(IExecutionContext executionContext, Exception exception)
   at Amazon.Runtime.Internal.ErrorHandler.ProcessExceptionAsync(IExecutionContext executionContext, Exception exception)
   at Amazon.Runtime.Internal.ErrorHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.Signer.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.EndpointDiscoveryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CredentialsRetriever.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.RetryHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.CallbackHandler.InvokeAsync[T](IExecutionContext executionContext)  
   at Amazon.S3.Internal.AmazonS3ExceptionHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.ErrorCallbackHandler.InvokeAsync[T](IExecutionContext executionContext)
   at Amazon.Runtime.Internal.MetricsHandler.InvokeAsync[T](IExecutionContext executionContext)
   at OrchardCore.FileStorage.AmazonS3.AwsFileStore.TryDeleteDirectoryAsync(String path)
   at OrchardCore.Media.Core.DefaultMediaFileStore.TryDeleteDirectoryAsync(String path)
   at OrchardCore.Media.Handlers.AttachedMediaFieldContentHandler.RemovedAsync(RemoveContentContext context)
   at OrchardCore.Modules.InvokeExtensions.InvokeAsync[TEvents,T1](IEnumerable`1 events, Func`3 dispatch, T1 arg1, ILogger logger)
@Piedone
Copy link
Member

Piedone commented Jan 28, 2024

It seems we just need to wrap it into a:

        if (listObjectsResponse.S3Objects.Count > 0)
        {

        }

Right?

If indeed, would you like to venture into submitting a PR for this?

AndreySurkov added a commit to AndreySurkov/OrchardCore that referenced this issue Feb 2, 2024
Piedone added a commit that referenced this issue Feb 2, 2024
* Skip DeleteObjectsAsync call if there are no items to delete

fixes #15169

* Formatting

---------

Co-authored-by: Zoltán Lehóczky <[email protected]>
urbanit pushed a commit to urbanit/OrchardCore that referenced this issue Mar 18, 2024
…CMS#15239)

* Skip DeleteObjectsAsync call if there are no items to delete

fixes OrchardCMS#15169

* Formatting

---------

Co-authored-by: Zoltán Lehóczky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants