JVips
JVips copied to clipboard
Crash on multithreaded execution
Lib crashed when execute on > 1 thread something like this
executor.execute(() -> {
try (FileChannel ch = FileChannel.open(path, READ);
VipsImage image = new VipsImage(ch.map(READ_ONLY, 0, ch.size()), (int) ch.size())) {
image.resize(new Dimension(300, 300), true)
}});
What is the format of the test image? Does is crash with a SIGSEGV?
Any jpeg (I have some pngs and gifs, but mostly jpegs) It crashed as SIGSEGV. Single thread is OK. Tested on linux with 2 and 4 threads - hard crash.
I can reproduce using an ExecutorService with a CompletionService. We aren't using byte buffers in production but byte arrays where we haven't any crash in MT context. I will have a look when I have the time.
I suspect an early FileChannel closing in the try-with resources statement which unmaps the memory. The JVM seems to crash after unmap.
In command line, it sometimes throws several CloseChannelException instead of sigsegv. Moreover, I see several unmap() calls with stace before the crash.
Hi, thanks for investigating the problem! Maybe it is worth to change JVips API to prevent unmap problems?
I will have a look how to handle this case and what is possible to do