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

"ERROR Could not add media to cache." when Dianoga is unable to optimize an image due to a processing error #34

Closed
mjarosch opened this issue Mar 21, 2018 · 7 comments

Comments

@mjarosch
Copy link

Anytime the command line optimizers exit with an error code, we are seeing an exception in SC trying to add it to the cache and get the yellow page of death. For example, if a PNG file is uploaded to the media library with a JPG extension (I know, I have reported it to the content team to fix, but still), attempting to download or view it will error.

3632 09:18:56 ERROR Dianoga: Unable to optimize /path/to/image due to a processing error! It will be unchanged.
Exception: System.InvalidOperationException
Message: E:\path\to\site\Website\App_Data\Dianoga Tools\PNGOptimizer\PNGOptimizerCL.exe exited with unexpected exit code 1. Output:

(KO) Unsupported file format

Optimizing tmp3DEC.png
Source: Dianoga
at Dianoga.Optimizers.CommandLineToolOptimizer.ExecuteProcess(String arguments)
at Dianoga.Optimizers.CommandLineToolOptimizer.ProcessOptimizer(OptimizerArgs args)
at Dianoga.Optimizers.OptimizerProcessor.Process(OptimizerArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
at Dianoga.Processors.Pipelines.DianogaOptimize.ExtensionBasedOptimizer.ProcessOptimize(ProcessorArgs args)
at (Object , Object[] )
at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
at Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain)
at Dianoga.MediaOptimizer.Process(MediaStream stream, MediaOptions options)

3632 09:18:56 ERROR Could not add media to cache. Media item id: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
Exception: System.ObjectDisposedException
Message: Cannot access a closed Stream.
Source: mscorlib
at System.IO.__Error.StreamIsClosed()
at System.IO.MemoryStream.get_Length()
at Sitecore.IO.StreamSharer..ctor(Stream masterStream, String bufferFilePath)
at Sitecore.Resources.Media.MediaCacheRecord.Initialize(Media sitecoreMedia, MediaOptions mediaOptions, MediaStream mediaStream)
at Sitecore.Resources.Media.MediaCache.CreateCacheRecord(Media media, MediaOptions options, MediaStream stream)
at Sitecore.Resources.Media.MediaCache.AddStream(Media media, MediaOptions options, MediaStream stream, MediaStream& cachedStream)
at Sitecore.Resources.Media.Media.AddStreamToCache(MediaOptions options, MediaStream mediaStream, MediaStream& cachedStream)

@kamsar
Copy link
Owner

kamsar commented Oct 7, 2018

@mjarosch I tried this just now and was unable to reproduce.

Specifically, I:

  • Installed the latest Dianoga from source to the latest prerelease version of Sitecore, with the default settings
  • Took a png file and renamed it to jpg
  • Uploaded it into the media library
  • Result: I got the exit code 1 logs...but not the closed stream logs and the media was operational

I also tried the opposite - making a fake png from a jpeg, since your logs were invoking PNGOptimizerCL.exe. It also worked.

What Sitecore version are you using?

@mjarosch
Copy link
Author

mjarosch commented Oct 8, 2018

@kamsar We were running 8.2 Update 2 at the time I reported the issue. We have since upgraded to 9.0 Update 1, and haven't had an opportunity to see if it is still happening.

@josedbaez
Copy link

I got the issue @mjarosch mentioned but re-added the latest 4.0 nuget package and error is gone now...

@mzizka
Copy link

mzizka commented Dec 17, 2018

Still have this issue in the latest. In my case, I have an image that nQuant is unable to process. In asynchronous mode, the optimizer fails gracefully and the original image is produced and cached. A message is logged once and is never seen again for that same image.

But in synchronous mode, the image can't load or be cached, and I get the following error sequence each time:

[14352] 15:28:19 ERROR Dianoga.MediaOptimizer - Dianoga: Unable to optimize /XXX/XX/XXXXX due to a processing error! It will be unchanged.
Exception: nQuant.QuantizationException
Message: The image you are attempting to quantize does not contain a 32 bit ARGB palette. This image has a bit depth of 24 with 0 colors.
Source: nQuant.Core
   ...

[14352] 15:28:19 ERROR Sitecore.Resources.Media.ImageMedia - Could not add media to cache. Media item id: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}
Exception: System.ObjectDisposedException
Message: Cannot access a closed Stream.
Source: mscorlib
   ...
   at Sitecore.IO.StreamSharer..ctor(Stream masterStream, String bufferFilePath)
   at Sitecore.Resources.Media.MediaCacheRecord.Initialize(Media sitecoreMedia, MediaOptions mediaOptions, MediaStream mediaStream)
   ...

[14352] 15:28:19 ERROR Sitecore.Nexus.Web.HttpModule - Application error.
Exception: System.ObjectDisposedException
Message: Cannot access a closed Stream.
Source: mscorlib
   ...
   at Sitecore.Resources.Media.Streaming.RangeRetrievalResponse.WriteFullContent(HttpContext context, Stream fileContent)
   at Sitecore.Resources.Media.MediaRequestHandler.DoProcessRequest(HttpContext context, MediaRequest request, Media media)
   ...

@bartlomiejmucha
Copy link
Contributor

@mjarosch why not to disable Dianoga completely on the CM server? It wastes CPU, especially if you use jpegoptim lossy compression. You need to optimize images mostly for SEO on CD servers.
If you have a standalone instance, check out my #41 it allows to enable Dianoga per site.

@markgibbons25
Copy link
Collaborator

Looks like this might be happening due to a race condition https://kb.sitecore.net/articles/843582

@markgibbons25
Copy link
Collaborator

I did find an issue here, it should be fixed https://github.com/kamsar/Dianoga/releases/tag/5.0.0-beta.1 please retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants