rmagick / rmagick

Ruby bindings for ImageMagick
https://rmagick.github.io/
MIT License
696 stars 140 forks source link

"stack level too deep" when calling Magick::Image.read within a fiber (Ruby 1.9.3-p0) #22

Closed bf4 closed 5 years ago

bf4 commented 9 years ago

Issue by mamu Wednesday Nov 30, 2011 at 01:28 GMT Originally opened as https://github.com/rmagick/rmagick/issues/38


Hi!

I'm not exactly sure what's going on since I get inconsistent results between my Linux dev box and my OS X dev box, both running the same version of Ruby (1.9.3-p0), both using rvm, both running the same version of RMagick (2.13.1), and both running the same version of ImageMagick (6.7.1, compiled from source).

My OS X dev box plays along nicely, but my Linux dev box throws a "stack level too deep" exception when I call Magick::Image.read within a fiber. I'm using the fiber to untangle evented code in a fashion quite similar to igrigorik's em-synchrony project), so this is all being done within the context of EventMachine's event loop. If I downgrade to Ruby 1.9.2-p290 on my Linux box, RMagick begins to work fine again.

Really at quite a loss why OS X would behave but Linux wouldn't. I don't know what else I ought to provide to help track down the issue, but I'd be happy to post anything extra anyone requests.

Thanks!

bf4 commented 9 years ago

Comment by rmagick Thursday Dec 01, 2011 at 01:33 GMT


It maybe that you disabled openmp when installing on OS X but not for your linux. Try re-installing imagemagick on the linux box by setting --disable-openmp when doing the configure.

Moncef

-----Original Message----- From: Michael Amundson [mailto:reply@reply.github.com] Sent: Tuesday, November 29, 2011 8:29 PM To: rmagick Subject: [rmagick] "stack level too deep" when calling Magick::Image.read within a fiber (Ruby 1.9.3-p0) (#38)

Hi!

I'm not exactly sure what's going on since I get inconsistent results between my Linux dev box and my OS X dev box, both running the same version of Ruby (1.9.3-p0), both using rvm, both running the same version of RMagick (2.13.1), and both running the same version of ImageMagick (6.7.1, compiled from source).

My OS X dev box plays along nicely, but my Linux dev box throws a "stack level too deep" exception when I call Magick::Image.read within a fiber. I'm using the fiber to untangle evented code in a fashion quite similar to igrigorik's em-synchrony project), so this is all being done within the context of EventMachine's event loop. If I downgrade to Ruby 1.9.2-p290 on my Linux box, RMagick begins to work fine again.

Really at quite a loss why OS X would behave but Linux wouldn't. I don't know what else I ought to provide to help track down the issue, but I'd be happy to post anything extra anyone requests.

Thanks!


Reply to this email directly or view it on GitHub: https://github.com/rmagick/rmagick/issues/38

bf4 commented 9 years ago

Comment by mamu Monday Dec 05, 2011 at 04:25 GMT


OpenMP is enabled on my OS X installation of ImageMagick (just checked using identify -version). I'll give Linux a go with OpenMP disabled and see if that cures things. Thanks for the suggestion!

bf4 commented 9 years ago

Comment by tammofreese Friday Jan 20, 2012 at 16:24 GMT


I am facing the same problem, and disabling openmp hasn't helped. @mamu has it worked for you, or have you found another solution?

bf4 commented 9 years ago

Comment by mamu Friday Jan 20, 2012 at 16:25 GMT


@tammofreese I unfortunately had no luck after disabling OpenMP on Linux. I reverted to Ruby 1.9.2-p290 until it's fixed.

bf4 commented 9 years ago

Comment by tammofreese Friday Jan 20, 2012 at 17:54 GMT


I can reproduce the error in irb with this script (Debian Squeeze 64 bit, Ruby 1.9.3p0, RMagick 2.13.1, ImageMagick 6.7.4-7):

require 'RMagick' include Magick

def load_image image_data = File.open('image.jpg','rb') { |f| f.read } Image.from_blob(image_data) end

x = load_image # => [ JPEG 500x500 500x500+0+0 DirectClass 8-bit 71kb]

f = Fiber.new { load_image } x = f.resume # SystemStackError: stack level too deep

bf4 commented 9 years ago

Comment by fugufish Thursday Mar 22, 2012 at 22:49 GMT


+1 seems to be specific to 1.9.3. Any chance of getting this fixed?

bf4 commented 9 years ago

Comment by tammofreese Thursday Mar 22, 2012 at 23:27 GMT


For me it works fine for me with Ruby 1.9.3p on Lion, but fails with Ruby 1.9.3 on Debian.

bf4 commented 9 years ago

Comment by mamu Wednesday Jul 11, 2012 at 19:06 GMT


For some reason, this seems to not be an issue for me anymore. I'm now using Debian Squeeze (64-bit), Ruby 1.9.3p125, RMagick 2.13.1, and ImageMagick 6.6.0-4 (which is somewhat older than the 6.7.1 I was using before and the 6.7.4-7 tammofreese reported using). I don't know if perhaps this means it was related to the version of ImageMagick or perhaps the version of Ruby. Either way, I'm glad I can finally upgrade to 1.9.3!

Has anyone else tried an older version of ImageMagick or a new version of Ruby or both?

bf4 commented 9 years ago

Comment by tammofreese Thursday Jul 12, 2012 at 13:05 GMT


I still get the error with Debian Squeeze (64-bit), Ruby 1.9.3p125, RMagick 2.13.1, and ImageMagick 6.7.4-7. Which options have you passed to ./configure when installing ImageMagick?

bf4 commented 9 years ago

Comment by mamu Thursday Jul 12, 2012 at 14:09 GMT


Woops! So my fix was likely a bug in my code that inadvertently caused RMagick to not be operating within a fiber. Sorry for the false hopes. Still baffling why the same versions on OS X aren't impacted.

bf4 commented 9 years ago

Comment by sholden Thursday Aug 02, 2012 at 23:39 GMT


I think I'm running into this same issue. I'm a little confused as to your fix, @mamu

You got it working by putting it INTO a fiber?

bf4 commented 9 years ago

Comment by tiagoluchini Monday Dec 03, 2012 at 20:51 GMT


Very same issue here. RMagick worked great inside a fiber until I upgraded to ruby 1.9.3. It continues to work on my Lion but fails at Heroku (which runs on Linux).

Watson1978 commented 5 years ago

I tried the test code in https://github.com/rmagick/rmagick/issues/22#issuecomment-50021997.

require 'rmagick'

def load_image
  image_data = File.open('sample.jpg','rb') { |f| f.read }
  Magick::Image.from_blob(image_data)
end

x = load_image # => [ JPEG 500x500 500x500+0+0 DirectClass 8-bit 71kb]

f = Fiber.new { load_image }
x = f.resume # SystemStackError: stack level too deep

p Magick::Version
p :ok

However, I can't the reproduce this issue with Ruby 2.3 and RMagick 3.0.0.

$ ruby -v thumbnail.rb
ruby 2.3.8p459 (2018-10-18 revision 65136) [x86_64-darwin18]
"RMagick 3.0.0"
:ok

I will close this issue. But, feel free to reopen if you met the same issue.