ruby-vips: Writing hangs forever

Hi,

I’ve been encountering an issue with writing hanging forever. Nothing too special, it happened at first with the image processing pipeline of rails.

Vips is installed via Homebrew, on an up-to-date Mac Mini M1.

# vips --version    
vips-8.11.2-Sat Jul  3 14:17:10 UTC 2021
# vips --vips-config
enable debug: no
enable deprecated library components: yes
enable modules: no
use fftw3 for FFT: yes
accelerate loops with orc: yes
ICC profile support with lcms: yes (lcms2)
zlib: yes
text rendering with pangocairo: yes
font file support with fontconfig: yes
RAD load/save: yes
Analyze7 load/save: yes
PPM load/save: yes
GIF load:  yes
EXIF metadata support with libexif: yes
JPEG load/save with libjpeg: yes (pkg-config)
JXL load/save with libjxl: no (dynamic module: no)
JPEG2000 load/save with libopenjp2: yes
PNG load with libspng: yes
PNG load/save with libpng: yes (pkg-config libpng >= 1.2.9)
PNG quantisation to 8 bit: yes
TIFF load/save with libtiff: yes (pkg-config libtiff-4)
image pyramid save: yes
HEIC/AVIF load/save with libheif: yes (dynamic module: no)
WebP load/save with libwebp: yes
PDF load with PDFium:  no
PDF load with poppler-glib: yes (dynamic module: no)
SVG load with librsvg-2.0: yes
EXR load with OpenEXR: yes
OpenSlide load: yes (dynamic module: no)
Matlab load with matio: yes
NIfTI load/save with niftiio: no
FITS load/save with cfitsio: yes
Magick package: MagickCore (dynamic module: no)
Magick API version: magick7
load with libMagickCore: yes
save with libMagickCore: yes

Gem version: ruby-vips (2.1.2)

To reproduce, in rails console:

> Vips.version_string
"8.11.2-Sat Jul  3 14:17:10 UTC 2021"
> im = Vips::Image.jpegload("/Users/maxime/xxx/photo-1491933382434-500287f9b54b.jpg")
=> #<Image 1000x1250 uchar, 3 bands, srgb>
> im.write_to_file("/Users/maxime/xxx/test.jpg")
=> hang

Vips works in CLI:

vips rot photo-1491933382434-500287f9b54b.jpg x.jpg d90

Edit: Vips works in std irb:

> require "vips"
=> true
> Vips.version_string
"8.11.2-Sat Jul  3 14:17:10 UTC 2021"
> im = Vips::Image.jpegload("/Users/maxime/xxx/photo-1491933382434-500287f9b54b.jpg")
=> #<Image 1000x1250 uchar, 3 bands, srgb>
> im.write_to_file("/Users/maxime/xxx/test.jpg")
=> nil

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 1
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Yes, 8.11 has a new and faster threading system which starts up earlier in the libvips lifecycle. Rolling back to 8.10 should fix it, I think (or waiting for 8.11.3, or disabling fork. etc.)

I’m having this error too – thought I was losing my mind until I found this issue!

I can repro/fix the same way with rails c, but I haven’t been able to get Rails working again. I think I need to disable forking in Puma or something.

How’s the fix looking? Was this issue introduced in a recent version that I could roll back before?

Hi @maximeg, thanks for reporting this.

I think this is perhaps fork. My guess is:

  • rails starts up and loads ruby-vips
  • ruby-vips inits a range of thread resources to get ready for processing
  • rails forks to handle a request
  • the new process is a photocopy of the forking process, but all of the thread resources are broken, since you can’t thread across fork
  • ruby-vips now tries to process an image, but no thread stuff is working, and locks

We have a possible fix for this in 8.11.3 (as yet unreleased). If you are OK with editing your homebrew vips.rb formula, you could try that. Alternatively, 8.11.3 ought to be out fairly soon. You can also work around this by disabling spring (which will stop the rails fork behaviour).