Bug 22524 - Image.FromStream() appears to be hanging
Summary: Image.FromStream() appears to be hanging
Status: RESOLVED INVALID
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: 3.8.0
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-29 21:09 UTC by troy-dawson
Modified: 2014-10-04 11:03 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
test project (6.47 KB, application/zip)
2014-08-29 21:09 UTC, troy-dawson
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description troy-dawson 2014-08-29 21:09:22 UTC
Created attachment 7876 [details]
test project

The attached sample project just hangs at this call:

			Console.WriteLine("Got image bytes (size {0}); converting to image", content.Length);	
		
			var image = Image.FromStream(content);
			
			Console.WriteLine("Finished converting image");	

Console Output:

Getting http://www.google.com/images/srpr/logo11w.png . . .
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/3.8.0/lib/mono/gac/System/4.0.0.0__b77a5c561934e089/System.dll [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/3.8.0/lib/mono/gac/System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll [External]
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/3.8.0/lib/mono/gac/System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll [External]
Thread started:  #2
Thread started: <Thread Pool> #3
Thread started: <Thread Pool> #4
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/3.8.0/lib/mono/gac/Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll [External]
Thread started: <Thread Pool> #5
Thread started: <Thread Pool> #6
Got image bytes (size 14022); converting to image


My environment is Mono / Net 4.5 on OS X 10.10

This sample runs fine on Xamarin Studio 5.4 on Windows 7.
Comment 1 Zoltan Varga 2014-09-01 11:29:13 UTC
Cannot reproduce this on mono 3.8.0 on mavericks.
Comment 2 troy-dawson 2014-09-01 11:43:23 UTC
Still hanging for me but running the attached project from the terminal I get an exception:

Troys-MacBook-Pro:Debug troy$ mono FileGrabber.exe
Getting http://www.google.com/images/srpr/logo11w.png . . .
Got image bytes (size 14022); converting to image

Unhandled Exception:
System.AggregateException: One or more errors occurred ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at FileGrabber.MainClass+<GetImageAsync>c__async1.MoveNext () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.Wait (Int32 millisecondsTimeout, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.Task.Wait () [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.Task`1[System.Drawing.Image].get_Result () [0x00000] in <filename unknown>:0 
  at FileGrabber.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
 --> (Inner exception 0) System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at FileGrabber.MainClass+<GetImageAsync>c__async1.MoveNext () [0x00000] in <filename unknown>:0 

[ERROR] FATAL UNHANDLED EXCEPTION: System.AggregateException: One or more errors occurred ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at FileGrabber.MainClass+<GetImageAsync>c__async1.MoveNext () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Threading.Tasks.Task.Wait (Int32 millisecondsTimeout, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.Task.Wait () [0x00000] in <filename unknown>:0 
  at System.Threading.Tasks.Task`1[System.Drawing.Image].get_Result () [0x00000] in <filename unknown>:0 
  at FileGrabber.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
 --> (Inner exception 0) System.TypeInitializationException: An exception was thrown by the type initializer for System.Drawing.GDIPlus ---> System.DllNotFoundException: libgdiplus.dylib
  at (wrapper managed-to-native) System.Drawing.GDIPlus:GdiplusStartup (ulong&,System.Drawing.GdiplusStartupInput&,System.Drawing.GdiplusStartupOutput&)
  at System.Drawing.GDIPlus..cctor () [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in <filename unknown>:0 
  at FileGrabber.MainClass+<GetImageAsync>c__async1.MoveNext () [0x00000] in <filename unknown>:0
Comment 3 troy-dawson 2014-09-01 11:50:13 UTC
Copying libgdiplus.0.dylib to the exe directory and running from the terminal hangs too.

mono-sgen is at 60% CPU utilization during the hang . . .
Comment 4 troy-dawson 2014-09-01 12:02:23 UTC
When I break the hanging app in XS Thread #4 is in System.Drawing.GDIPlus.GdiIplusStartup
Comment 5 troy-dawson 2014-09-01 12:03:39 UTC
^ GdiplusStartup
Comment 6 troy-dawson 2014-09-01 12:07:26 UTC
OK, now it's working fine with no code changes.

I re-DL'd the attached project again to verify.


GdiplusStartup might take a long time the first time it is run??
Comment 7 Zoltan Varga 2014-09-01 12:53:58 UTC
That is possible, it might be setting up font caches or something.
Comment 8 Rodrigo Kumpera 2014-10-03 08:32:46 UTC
This is fontconfig building its font cache. It's not a bug, it's how it works.

Make sure you have a valid usable cache in place and this won't happen.
Comment 9 troy-dawson 2014-10-03 20:27:27 UTC
Upon installing new mono version my test takes 2 full minutes to run on a stock 10.10 system.

This is really "suboptimal" and unacceptable to ship with.
Comment 10 Rodrigo Kumpera 2014-10-04 09:21:25 UTC
Every time of just the first time?

Make sure that font config font caching can run fine.
Comment 11 troy-dawson 2014-10-04 11:03:48 UTC
The attached test project exhibits this behavior whenever I install a new mono update, I think.

This is acceptable for development but I can't tell my customers that the first run of the app will pause for 2 minutes while it builds GDI's font cache.