我正在使用用 ImageMagick 编译的 node.js、node-vips 和 libvips 来转换和调整图像大小。当我尝试调整多个图像的大小时,我遇到了分段错误和失败的断言。
我经历了很多不同的崩溃,我不知道从哪里开始。我从 libvips 7.26.8 开始,我也尝试过 7.30.7。这是从源代码编译的节点 v0.8.17,在一个相当标准、干净的 ubuntu 盒子上。
#0 0x0000158ac3765c59 in ?? ()
Cannot access memory at address 0x7fffa837ec90
#0 0x0000000000000000 in ?? ()
#1 0x0000000000000000 in ?? ()
node: ../deps/uv/src/unix/stream.c:729: uv__stream_io: Assertion `!!(events & EV_READ) ^ !!(events & EV_WRITE)' failed.
Aborted (core dumped)
#0 0x00007f5ed4df9425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007f5ed4dfcb8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007f5ed4df20ee in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007f5ed4df2192 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x00000000005d1bc8 in uv__stream_io (loop=<optimized out>, w=<optimized out>, events=<optimized out>) at ../deps/uv/src/unix/stream.c:729
#5 0x00000000005c6ac2 in ev_invoke_pending (loop=0xdb34c0 <default_loop_struct>) at ../deps/uv/src/unix/ev/ev.c:2145
#6 0x00000000005c2986 in uv__poll (loop=0xdb27e0 <default_loop_struct>) at ../deps/uv/src/unix/core.c:246
#7 uv__run (loop=0xdb27e0 <default_loop_struct>) at ../deps/uv/src/unix/core.c:257
#8 0x00000000005c2c60 in uv_run (loop=0xdb27e0 <default_loop_struct>) at ../deps/uv/src/unix/core.c:265
#9 0x000000000057d9f7 in node::Start(int, char**) ()
#10 0x00007f5ed4de476d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#11 0x0000000000575245 in _start ()
#0 0x00000000006b13b8 in v8::Object::SetHiddenValue(v8::Handle<v8::String>, v8::Handle<v8::Value>) ()
#1 0x0000000000593f5a in node::SlabAllocator::Allocate(v8::Handle<v8::Object>, unsigned int) ()
#2 0x0000000000591d04 in node::StreamWrap::OnAlloc(uv_handle_s*, unsigned long) ()
#3 0x00000000005d08fb in uv__read (stream=0x1fa7f90) at ../deps/uv/src/unix/stream.c:575
#4 0x00000000005d1a1a in uv__stream_io (loop=<optimized out>, w=<optimized out>, events=<optimized out>) at ../deps/uv/src/unix/stream.c:745
#5 0x00000000005c6ac2 in ev_invoke_pending (loop=0xdb34c0 <default_loop_struct>) at ../deps/uv/src/unix/ev/ev.c:2145
#6 0x00000000005c29df in uv__poll (loop=0xdb27e0 <default_loop_struct>) at ../deps/uv/src/unix/core.c:248
#7 uv__run (loop=0xdb27e0 <default_loop_struct>) at ../deps/uv/src/unix/core.c:257
#8 0x00000000005c2c60 in uv_run (loop=0xdb27e0 <default_loop_struct>) at ../deps/uv/src/unix/core.c:265
#9 0x000000000057d9f7 in node::Start(int, char**) ()
#10 0x00007f065aa1176d in __libc_start_main () from /lib/x86_64-linux-gnu/libc.so.6
#11 0x0000000000575245 in _start ()
我经常遇到前两个错误之一——即没有堆栈跟踪。这些都是在尝试调整 6 个左右的图像大小时发生的——有时它们都成功而没有错误,但通常在调整前一两个图像大小后会出现故障。
我到底该如何调试呢?
在 node-vips 插件的单元测试中,有一条评论如下:
如果使用 imagemagick 支持编译 vips,此测试将崩溃,因为从 libeio 调用时 imagemagick 崩溃
为什么是这样?这仍然是真的吗?我认为 ImageMagick 是完全线程安全的,但它如何使它从 libeio/libuv 调用不安全?