Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack level too deep when using carrierwave versions

I'm trying to use a sidekiq worker, which more or less saves a image file to database (using carrierwave). There are few files to save, which are a keyframes extracted from a video file. That's what that worker is about.

My image uploader has a few versions defined and looks as follows:

class KeyframeUploader < CarrierWave::Uploader::Base

  # ...

  # Keyframe thumbnail sizes
  version :small do
    process resize_to_fill: [180, 180], if: :square?
    process resize_to_fill: [320, 180], if: :not_square?
  end

  version :medium do
    process resize_to_fill: [460, 460], if: :square?
    process resize_to_fill: [640, 460], if: :not_square?
  end

  version :large do
    process resize_to_fill: [720, 720], if: :square?
    process resize_to_fill: [1280, 720], if: :not_square?
  end


  private

    # Checks if image is a square
    def square? file
      img = Magick::Image.read(file.path)
      img[0].columns == img[0].rows
    end

    # Oposite to #square?
    def not_square? file
      !square? file
    end

end

The thing is, when i'm trying to run my Sidekiq Worker, it throws Celluloid::FiberStackError: stack level too deep and the only way to fix that is to remove my version definitions. It works only if there are not any version assigned to the uploader.

I have tried moving a save process to another worker or using Carrierwave::Backgrounder but i'm allways getting the same result.

Have you any idea what can i do about it?


Edit: My stracktrace is:

SystemStackError: stack level too deep from /usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/irb/workspace.rb:86

like image 460
mbajur Avatar asked Mar 05 '14 18:03

mbajur


2 Answers

It turned out, that it's a carrierwave's fault (well, actually, osx fault). Thread with explanation: https://github.com/carrierwaveuploader/carrierwave/issues/1330

Solution:

gem 'rmagick', :require => 'RMagick'
like image 136
mbajur Avatar answered Nov 20 '22 22:11

mbajur


i would target the for loop in your worker.

for i in 1..(frames_to_extract)

you're not incrementing i but you seem to be doing an indexed loop. I would switch it to use enum and each_with_index.

Rubyists tend to avoid the for loop as its a nasty mess.

like image 1
engineerDave Avatar answered Nov 20 '22 22:11

engineerDave