Race condition in the dynamic resizer

Bug #1529934 reported by François Marier on 2015-12-29
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Libravatar
High
Unassigned

Bug Description

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 109, in get_response
    response = callback(request, *callback_args, **callback_kwargs)

  File "/usr/share/libravatar/libravatar/public/views.py", line 277, in resize
    (resized_filename, file_format) = resized_avatar(email_hash, size)

  File "/usr/share/libravatar/libravatar/public/views.py", line 235, in resized_avatar
    resized_img = Image.open(resized_filename)

  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1980, in open
    raise IOError("cannot identify image file")

IOError: cannot identify image file

It looks like what is happening is that the resized_avatar() function queues up a resize job and then immediately tries to open the image without waiting for it to exist:

    # If the resized avatar already exists, don't re-generate it
    if not os.path.isfile(resized_filename):
        gm_client = libgearman.Client()
        for server in settings.GEARMAN_SERVERS:
            gm_client.add_server(server)

        workload = {'email_hash': email_hash, 'size': size}
        gm_client.do('resizeavatar', json.dumps(workload))

    resized_img = Image.open(resized_filename)

We need to find a way to make that gm_client.do() call block until it's done, or not use gearman here.

François Marier (fmarier) wrote :

> We need to find a way to make that gm_client.do() call block until it's done

Now that bug 1532640 is fixed, this should be fairly easy since the python-gearman API is much better:

  https://pythonhosted.org/gearman/client.html

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers