What have you found for these years?

2012-09-28

Mysterious Heroku issue with paperclip

This troubles me for a long, long while. Finally I decided to look into it.
But the more I looked into it, the more I don't understand what's going on.

Anyway, I found a workaround. Don't ask me why this monkey patch
would do anything, but it really works... Hey, programming is really alchemy,
sometimes it's really too hard to explain something.

And this patch is only needed for Heroku as far as I know. It's not needed for
my Mac and an Arch Linux located on Rackspace which I have an access.
Ruby versions are exactly the same, 1.9.3p194.

In short, just spawn a random subprocess to do anything, echo would work, too.
module Paperclip
  class AbstractAdapter
    def copy_to_tempfile(src)
      FileUtils.cp(src.path, destination.path)
      # try to spawn a subprocess to make underlying `identify` process work
      `echo`
      destination
    end
  end
end
I have no idea why it would work. It sounds to me like a Ruby or... Heroku bug
which related to their setup. I am not sure if I should put this patch on production,
since it's really too mysterious...

I suspect that this has something to do with flushing or so, but I cannot figure it out.
It seems that spawning process via Process.spawn would fail if we don't spawn
a process via Kernel#` first. Maybe this is really a Ruby bug for some
OSes or libraries version. I guess I would stop tracing here...

0 retries:

Post a Comment

All texts are licensed under CC Attribution 3.0