When using an async conversion plugin, there is an area of the file conversion API that can cause a race condition (and in my test environment, it happens to happen every time...).
So basically there are two flows that happen here. One for the client side 'is this document converted' looks like this (really dumbed down to the important bits):
- converter::start_conversion() calls conversion::get_conversions_for_file() to see if there are any existing conversions
- conversion::get_conversions_for_file() does a large multi-join and UNION query that looks for two things (in one query). On a large system, this may take a while:
- Any records in mdl_file_conversion for the source file id and the dest file format
- Find any existing conversioned files that happen to not have a record in mdl_file_conversion
- Anything found in step 2 is returned to converter::start_conversion()
- If more than 1 record is returned, then they are all deleted and it starts a new conversion.
- If just 1 record is returned, then converter::poll_conversion is called
- converter::poll_conversion will always call $conversion->update() if the conversion is in progress.
From on the async converter side, we:
- Mark the conversion as started in the DB (using an internal data field)
- Do the actual conversion (this may take some time)
- Load the converted file into the conversion (conversion::store_destfile_from_path())
- Save to the database
Now because of the particular timing, this is the order of what happens:
- Client Thread: First conversion request comes in from client, queued up, and returned as IN_PROGRESS
- Converter Thread: Converter picks up task and marks it started
- Client Thread: Second client request comes in, asking for the conversion
- Client Thread: conversion::get_conversions_for_file() starts its' big query
- Converter Thread: Completes conversion, ingests it, and saves destfileid and the completion status to the DB
- Client Thread: Big query returns, having only found the 1 conversion without the destfileid set, and also doesn't find the completed file (since these steps both happened while the query was in progress).
- Client Thread: converter::poll_conversion calls update() on the conversion object, which saves it to the DB. This overwrites the destfileid to blank (and resets the status), because the local object is blank, even though it has been updated in the database.
From then on, for each subsequent query (once a second in the assign interface), the big query finds 2 records, one for the conversion that it feels is 'incomplete', and one for the already converted file. This causes a force reset to happen, which deletes the waiting conversions and submits a new one, and this just happens over and over again, for as long as you leave the browser open.