Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault during tile extraction #91

Closed
jamesdolezal opened this issue Feb 17, 2021 · 2 comments
Closed

Segmentation fault during tile extraction #91

jamesdolezal opened this issue Feb 17, 2021 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@jamesdolezal
Copy link
Owner

jamesdolezal commented Feb 17, 2021

When tile extraction is performed with a high thread count, segmentation faults are common. Traceback highlights the fault as originating in slide/__init__.py, line 729:

region = region.resize(float(self.size_px) / self.extract_px)

Tracing the call through a debugger identifies vips/voperation.py, line 290 as the culprit:

vop = vips_lib.vips_cache_operation_build(op.pointer)

Which gives the following backtrace:

#1  0x00007fc9b55e3859 in __GI_abort () at abort.c:79
#2  0x00007fc9b564e3ee in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7fc9b5778285 "%s\n") at ../sysdeps/posix/libc_fatal.c:155
#3  0x00007fc9b565647c in malloc_printerr (str=str@entry=0x7fc9b577a670 "double free or corruption (out)") at malloc.c:5347
#4  0x00007fc9b5658120 in _int_free (av=0x7fc9b57a9b80 <main_arena>, p=0x7fc85c057fb0, have_lock=<optimized out>) at malloc.c:4314
#5  0x00007fc87cf056c5 in vips_cache_trim () at cache.c:775
#6  0x00007fc87cf05f44 in vips_cache_operation_add (operation=<optimized out>) at cache.c:879
#7  0x00007fc87cf06080 in vips_cache_operation_buildp (operation=0x7fc8f2ffb460) at cache.c:921
#8  vips_cache_operation_buildp (operation=operation@entry=0x7fc8f2ffb460) at cache.c:894
#9  0x00007fc87cf0c44d in vips_call_required_optional (operation=operation@entry=0x7fc8f2ffb460, required=required@entry=0x7fc8f2ffb490, optional=optional@entry=0x7fc8f2ffb570)
    at operation.c:880
#10 0x00007fc87cf0cb77 in vips_call_by_name
    (operation_name=<optimized out>, option_string=option_string@entry=0x0, required=required@entry=0x7fc8f2ffb490, optional=optional@entry=0x7fc8f2ffb570) at operation.c:920
#11 0x00007fc87cf0cfe0 in vips_call_split (operation_name=operation_name@entry=0x7fc87cf41e0c "shrinkh", optional=optional@entry=0x7fc8f2ffb570) at operation.c:1024
#12 0x00007fc87cdddbcb in vips_shrinkh (in=in@entry=0x7fc84c3f54d0, out=out@entry=0x7fc84c3f3898, hshrink=hshrink@entry=2) at shrinkh.c:367
#13 0x00007fc87cddaa2a in vips_resize_build (object=0x7fc79828e2d0) at resize.c:195
#14 0x00007fc87cef9c8d in vips_object_build (object=0x7fc79828e2d0) at object.c:367
#15 0x00007fc87cf06070 in vips_cache_operation_buildp (operation=0x7fc8f2ffb718) at cache.c:918
#16 vips_cache_operation_buildp (operation=0x7fc8f2ffb718) at cache.c:894
#17 0x00007fc87cf060c0 in vips_cache_operation_build (operation=<optimized out>) at cache.c:948
#18 0x00007fc882952dec in ffi_call_unix64 () at /home/shawarma/venv/lib/python3.8/site-packages/cffi.libs/libffi-806b1a9d.so.6.0.4
#19 0x00007fc882951f55 in ffi_call () at /home/shawarma/venv/lib/python3.8/site-packages/cffi.libs/libffi-806b1a9d.so.6.0.4
#20 0x00007fc882b74a96 in cdata_call (cd=0x7fc95722e330, args=<optimized out>, kwds=<optimized out>) at c/_cffi_backend.c:3153

The issue appears to be that the vips resize() method is somehow thread unsafe. I think the libvips operation cache may be the core issue.

I have confirmed that disabling the resize() call in line 729 of slide/__init__.py prevents the segmentation faults.

Things to try include:

@jamesdolezal jamesdolezal added the bug Something isn't working label Feb 17, 2021
@jamesdolezal jamesdolezal self-assigned this Feb 17, 2021
@jamesdolezal
Copy link
Owner Author

Setting pyvips.cache_set_max(0) does not fix the issue.

Using thumbnail instead of resize does seem to fix the segmentation faults. Will need to test to assure quality between resize() and thumbnail() is appropriately comparable before resolving the issue and pulling into master.

jamesdolezal added a commit that referenced this issue Feb 17, 2021
- Fixes seg faults during tile extraction
- Fixes #91
@jamesdolezal
Copy link
Owner Author

Confirming that switching from resize() to thumbnail() fixes the issue, with no change or degradation of final image quality. Fixed in ca9de0f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant