JVips icon indicating copy to clipboard operation
JVips copied to clipboard

Crash on multithreaded execution

Open bademux opened this issue 4 years ago • 6 comments

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)
		}});

bademux avatar Jul 27 '20 20:07 bademux

What is the format of the test image? Does is crash with a SIGSEGV?

dbouron avatar Jul 29 '20 13:07 dbouron

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.

bademux avatar Jul 29 '20 13:07 bademux

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.

dbouron avatar Aug 05 '20 20:08 dbouron

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.

dbouron avatar Aug 06 '20 15:08 dbouron

Hi, thanks for investigating the problem! Maybe it is worth to change JVips API to prevent unmap problems?

bademux avatar Aug 07 '20 17:08 bademux

I will have a look how to handle this case and what is possible to do

dbouron avatar Aug 10 '20 13:08 dbouron