pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

0xC0000374 error code when access to image file is lost

Open LionelArn2 opened this issue 2 years ago • 2 comments

Hello :)

My python application is repetitively accessing a single TIFF image image stored on a network associated system (NAS) for long periods of time. It is likely that we'll experience a short interruption of connection at some point, and we'll temporarily lose access to the image file.

The app can handle the python exceptions raised by pyvips when the access to the NAS is lost, however occasionally the process is killed with a 0xC0000374 error code (heap corruption). Here's a minimal reproducible example; in my case, I launch this script and repeatedly disable and enable the access to the NAS:

import pyvips as vips

tiff_image_full_path = r"NAS\path\to\big_image.tiff"

while True:
    try:
        vips_image = vips.Image.tiffload(tiff_image_full_path, page=0, n=1, subifd=6)
        vips_image.write_to_memory()
    except Exception as e:
        print(f"Cannot load page: {e}")

Is there anything we can do to prevent this from happening?

LionelArn2 avatar Mar 08 '23 10:03 LionelArn2

Hello again @jcupitt,

I could reproduce this issue with a USB key instead of a NAS if this helps, this issue occurs systematically if I unplug the key while the script is running. Also, vips.cache_set_max_files(0) mitigates the issue for both NAS and USB cases, but the same error code still occurs in about ~30% of the interruptions. Empirically, I noticed that using larger images makes it more likely for the issue to occur.

If this helps, here's the code I used to created a sample image with which the issue is reproducible with the script of my first post (with both USB and NAS):

import pyvips as vips

image_path = r"output\path\to\big_image.tiff"
image_size = 2**15
n_pages = 8

image = vips.Image.gaussnoise(image_size, n_pages * image_size, mean=128, sigma=1)
image = image.cast("uchar")

image.tiffsave(
    image_path, 
    compression='lzw', 
    tile=True, 
    tile_width=512, tile_height=512, 
    pyramid=True, 
    subifd=True, 
    bigtiff=True, 
    page_height=image_size
)

Any advice would be greatly appreciated!

Edit: last info, it looks like the issue only occurs at the moment the connection to the NAS/USB key is re-established

LionelArn2 avatar Mar 21 '23 09:03 LionelArn2

Hi @LionelArn2,

I'll see if I can reproduce this. It's a tricky one to test :(

jcupitt avatar Mar 21 '23 10:03 jcupitt