MolSSI / QCFractal

A distributed compute and database platform for quantum chemistry.
https://molssi.github.io/QCFractal/
BSD 3-Clause "New" or "Revised" License
144 stars 47 forks source link

Lock task queue rows when requesting tasks #624

Closed bennybp closed 3 years ago

bennybp commented 3 years ago

Description

With the additional logging provided in the latest release, I do see multiple managers pulling down the same tasks. This is due to a race condition in queue_get_next where that code allows multiple managers to select the same records before updating them.

This PR hopefully solves this issue by using FOR UPDATE, which locks the selected rows until a commit is made.

See: Postgresql docs and sqlalchemy docs

Unfortunately, this is a really hard thing to test (requires multiple workers and multiple running servers connected to the same db) and so no test is added.

Changelog description

Fixes race condition resulting in multiple managers computing the same tasks

Status

codecov[bot] commented 3 years ago

Codecov Report

Merging #624 into master will increase coverage by 0.01%. The diff coverage is 100.00%.