Repository navigation
Description
Prerequisites
- I have written a descriptive issue title
- I have verified that I am running the latest version of ImageSharp
- I have verified if the problem exist in both
DEBUGandRELEASEmode - I have searched open and closed issues to ensure it has not already been reported
Description
I've encountered a strange bug when mutating images after migrating mvc app from net fw48 to net5 rc1. I've swapped to async image handling. Steps I do (async action on a controller):
1) await HttpContext.Request.ReadFormAsync()
2) Image<Rgba32> img = Image.Load<Rgba32>([first image from form].OpenReadStream(), out IImageFormat imgFormat);
3) await img.SaveAsync("some path"); // saves the image correctly
4) img.Mutate(x => x.Resize(w, h, s)); // thumbnail; used Bicubic, tried Lancoz3 to check if that could be the problem
5) await img.SaveAsync("thumbnail path");
// also tried alternative
5) await using FileStream stream = System.IO.File.Create("some path");
6) await img.SaveAsync(stream, imgFormat);Extremely frustrating is that this is happening only on production, not on my local machine. I've tried to use another sampler and use latest dev build of ImageSharp, neither helped. In each and every case the first half of an image is mutated correctly, while the other is either blank or filled with artifacts. I'm clueless about how should I move forward, the only option so far would be to go back to sync processing of images which I'd very much like to avoid. Attaching some test images:
Saved thumbnail 1:
Saved non-mutated image 1:
Saved thumbnail 2:
Saved non-mutated image 2:
Saved thumbnail 3:
Saved non-mutated image 3:
System Configuration
- dev: windows 10 20206_rsprerelease, net5 rc1
- production: windows server 2016 datacenter 10.0.14393, net5 rc1
ImageSharp version:
- tried 1.1, then 1.0.2 alpha 7






Activity
JimBobSquarePants commentedon Sep 16, 2020
It's hard to be sure by reading from your code sample but it looks to me like you are not disposing of your input stream nor the image.
Should be.
In the case of Image, the GC would collect everything eventually but it's wasteful so you should always dispose after using.
The stream though must be disposed of to ensure the content is all written from any internal buffers.
lofcz commentedon Sep 16, 2020
@JimBobSquarePants thanks, I've noticed that when I clone the image and then mutate the clonned copy it works properly both on dev and prod. Couldn't that be caused by
ConfigureAwait(false)ImageSharp is using when processing async save?JimBobSquarePants commentedon Sep 16, 2020
I couldn't tell you. Could you please post a complete sample so that we can correctly replicate and diagnose any issues.
klogeaage commentedon Sep 27, 2020
I can confirm this issue, which started occurring after I upgraded from Net Core 3.1 to 5.0 RC1. I am NOT using the async variants of the ImageSharp methods, except the controller if of course async, and I believe I am using/disposing of
ImageandStreamscorrectly. Going back to .Net Core 3.1 fixed the issue, but of course I would also like to move to 5.0.JimBobSquarePants commentedon Sep 27, 2020
I’ll need a means to replicate the issue. Without one nothing happens.
klogeaage commentedon Sep 27, 2020
Sure, I'll see if I can replicate in some unit tests.
JimBobSquarePants commentedon Sep 27, 2020
Thanks. That would be incredibly helpful!
klogeaage commentedon Sep 27, 2020
Argh, it's working fine in an Xunit test with just the imaging and stream operations :-(
So for what it's worth, here is my ResizeTo method:
And here is the simple test that is working with .Net Core 3.1 and .Net 5 RC1:
klogeaage commentedon Sep 27, 2020
And the code (fragment) that is not working in .Net 5.0 RC1:
All quite simple, I think. Very strange...
The only good thing is that it is going wrong very consistently in the Asp.Net production environment in Azure. So it is not an intermittent problem..
JimBobSquarePants commentedon Sep 27, 2020
I’m assuming you confirmed that the issue isn’t with the Azure upload by saving the output to the file system before uploading?
klogeaage commentedon Sep 27, 2020
No, I haven't, but it is uploading the original image as well as video and sound files with no issues, so I don't think there is an issue with that. Also, the Azure blob storage libraries are used extensively in many applications so any problem with those is likely to be reported and fixed very quickly.
And this has been working for months until earlier this week where I did the 5.0 update.
klogeaage commentedon Sep 27, 2020
@lofcz Could you please elaborate a little on the workaround you mentioned with Cloning the image?
JimBobSquarePants commentedon Sep 27, 2020
It’s best to check just to rule out any possibilities.
What is
ImageProcessor? What happens when you useLoadAsync?I wouldn’t recommend
Clonesince that creates an unnecessary copy.klogeaage commentedon Sep 27, 2020
ImageProcessoris simply my encapsulation of your library, i.e. it is a service class for the controller. Here it is:I don't use
LoadAsyncor any of the other async methods in ImageSharp, I probably should - do you think it could have a positive effect on this problem? It seems that @lofcz was using them, so now we know it doesn't seem to really influence this issue.P.S.
It's getting late here in Denmark, so don't expect any immediate response tonight.
37 remaining items
tocsoft commentedon Oct 1, 2020
looking like its the decoder that triggering the regression, if I generate a hash of pixel data after decoding be before any other process is ran then the hashes differ on 1cpu and are the same on 2 cpus
klogeaage commentedon Oct 1, 2020
Yes, indeed, you have deducted it absolutely right. So glad we are narrowing this down to something meaningful.
tannergooding commentedon Oct 1, 2020
We've got some people on the runtime team that are going to look further: dotnet/runtime#42912
For future reference, we don't strictly need a minimal repro on dotnet/runtime for an issue to be opened.
We'd much rather get an issue opened than not see it all, especially when we are this late in the release cycle 😄
This might be a more complex runtime bug, in which case finding a minimal repro might be difficult or impossible.
tocsoft commentedon Oct 1, 2020
@tannergooding Oh thanks for raising that I was planning to it myself one I had reduced it a little more.
tocsoft commentedon Oct 2, 2020
it definitely the JPEG decoder that's failing I've updated my reproduction repo to verify that's the case. https://github.com/tocsoft/Net5CorruptingImageSharp
brianpopow commentedon Oct 5, 2020
good news: It looks like with .Net 5.0 RC-2 this issue will be fixed!
Sergio0694 commentedon Oct 13, 2020
@JimBobSquarePants .NET 5 RC2 is out! 🚀🚀🚀
brianpopow commentedon Oct 13, 2020
I have tested this issue again with RC2 and can confirm the issue is gone. I will close the issue now.
Thanks to all who helped tracking down this issue!
Reproduction for #1356 with docker
Reproduction for #1356 with docker