This patch avoids problems with transactions by serializing access to the db. Note that it is necessary to serialize only within the same process, multiple processes do not interfere with each other.