Skip to content

test: fix macOS crash by preloading vips

Pierre de La Morinerie requested to merge fix-objc-test-crash into main

Fix this error when running the tests on macOS:

+[NSCheapMutableString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

Solution

Rails lazy-loads ruby-vips, which means the vips native library gets initialized in the forked processes (rather than once before the fork).

Loading it explicitly before the fork fixes the issue.

Methodology

the culprit was found by connecting lldb to the running test forked processes, and breaking when the error occurs.

$ lldb
> process attach --pid 14108

> b objc_initializeAfterForkError

> b dyld`dyld4::APIs::dlopen_from
> breakpoint command add 2.1
> > p (char*)$rsi
> > continue
> > DONE

> continue

The last library to be loaded is the culprit.

Edited by Pierre de La Morinerie

Merge request reports