Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows / Rails #328

Closed
charlie-prezzano opened this issue Jan 23, 2022 · 11 comments
Closed

Windows / Rails #328

charlie-prezzano opened this issue Jan 23, 2022 · 11 comments
Labels

Comments

@charlie-prezzano
Copy link

Hi,

My issue is that I cannot use vips as the active storage variant processor in development with my rails app. To note: (A) I can use mini magick in development, and (B) I can use vips in test (on Heroku).

Dev environment is Windows v11, RubyMine v2021.3.1, Ruby v3.1, Rails v7.0.1, libvips v8.12.1 ... then within Windows Env, I set PATH and RUBY_DLL_PATH to the libvips bin folder (C:\vips-dev-8.12\bin)

I can run a standalone ruby file that uses vips, but I cannot use vips within Rails.

When creating a variant the app crashes and I get: Process finished with exit code -1073741819 (0xC0000005). 0xC0000005 is an error code for an Access Violation exception.

Ex code that crashes: obj.image.variant(resize_to_fit: [20, 20]).processed.url

What is interesting is that the variant image is created. The second time the line of code is executed and will return the processed url.

I first was blaming ActiveStorage::AnalyzeJob, but turned it off with a monkeypatch found here: https://stackoverflow.com/questions/56445881/rails-how-to-disable-activestorage-analyzers-and-previewers.

In comparing the debug messages between mini magick and vips ... the only messages missing are:

DEBUG -- :   TRANSACTION (25.2ms)  BEGIN
DEBUG -- :   ActiveStorage::Blob Update (28.1ms)  UPDATE "active_storage_blobs" SET "metadata" = $1 WHERE "active_storage_blobs"."id" = $2  [["metadata", "{\"identified\":true,\"analyzed\":true}"], ["id", 179377]]
DEBUG -- :   TRANSACTION (24.3ms)  COMMIT

I cannot see how this SQL update crashes the rails app. What am I missing here?

Thank you for any help,
Charlie

@jcupitt
Copy link
Member

jcupitt commented Jan 23, 2022

Hi @charlie-prezzano,

Did you see #326 ? It might be a safer way to get libvips running inside Rails on Windows.

@charlie-prezzano
Copy link
Author

Hi @jcupitt,

Thanks again for your assistance. I am confident I am past #326 as I can successfully create the variant.

I'm also questioning if I successfully turned off ActiveStorage::AnalyzeJob. I'm going to take a deeper look in there. Perhaps this issue is in the wrong repository? I've searched rails issues and not finding anything that helps me. I'm gonna keep digging.

@jcupitt
Copy link
Member

jcupitt commented Jan 23, 2022

I was thinking that using the msys inside ruby to get ruby-vips installed might fix the rails issue, and you wouldn't need to mess with env vars. Changing PATH is especially tricky since it can trigger horrendous DLL conflicts.

So I'd suggest wiping libvips and ruby-vips from your system and not setting any env vars, then just adding ruby-vips to your rails gemfile. It should pull in everything for you (check the verbose output carefully).

@charlie-prezzano
Copy link
Author

I don't know why ... but Rails.application.config.active_storage.track_variants = false fixes the issue.

I forked rails and tried to debug with no avail. Down my rabbit hole I tried setting track_variants to false and it worked. I reverted back to Rails 7.0.1 and it works there too. I have no idea where the root issue is. I'm unsure if it is with Rails or Vips, but leaning towards Rails ... so closing the issue here.

@jcupitt
Copy link
Member

jcupitt commented Jan 24, 2022

Huh weird. Well, I'm glad it's working.

@charlie-prezzano
Copy link
Author

FYI ... setting track variants to false fixed this: obj.image.variant(resize_to_fit: [20, 20]).processed.url

Back in Rails 7.0.1 I was unable to run the below code ... but can on my forked Rails (7.1.0.alpha).

   def tinify(img, img_to_tinify)
      return if img.attachment.nil?
      Tinify.key = ENV['TINIFY_KEY']
      img_to_tinify.attach(
        io: StringIO.new(Tinify.from_url(img.url).to_buffer),
        filename: img.filename
      )
    end

I'm unsure why and need to move on. I'll circle back to switching from MiniMagick to vips on the next Rails release.

@charlie-prezzano
Copy link
Author

Last comment :)

I switched back to MiniMagick and came across an issue! I think the root problem is when a tempfile is deleted. I received the error message: C:/Ruby31-x64/lib/ruby/3.1.0/tempfile.rb:265:in unlink': Permission denied @ apply2files - C:/Users/xyz/AppData/Local/Temp/image_processing20220124-3028-rcfsz8.png (Errno::EACCES)`

Switching Ruby from 3.1.0 to Ruby 3.0.3 seems to fix everything ... so I am switching to vips :)

The issue should stay closed - it has nothing to do with vips. Vips could have better error messaging. Instead of throwing an exception it just crashes.

@jcupitt
Copy link
Member

jcupitt commented Jan 25, 2022

That's odd, I wonder why it crashed? libvips is supposed to catch errors like "unable to delete file" and return an error code. It's certainly a bug if it doesn't.

I added ruby 3.1 to testing 3206143 The ruby-vips tests seem to work under ruby 3.1 for linux hosts at least.

@kleisauke
Copy link
Member

It sound like the crash you were seeing might be resolved with libvips/libvips#2571 (an EACCES error during opening could result in a _get_osfhandle(-13) call, which triggers a security feature of UCRT). This PR landed in libvips v8.12.2.

@jcupitt
Copy link
Member

jcupitt commented Jan 25, 2022

Oh good point Kleis, I'd forgotten about that fix. I agree, 8.12.2 could fix it, binaries here:

https://github.com/libvips/libvips/releases/tag/v8.12.2

@ghost
Copy link

ghost commented May 3, 2023

manully download lastest version and replace them solve my issue
to C:\Ruby30-x64\msys64\mingw64\bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants