Repository navigation
Commit 3558907
parsemail: fix SeriesReference race with concurrent delivery
When multiple parsemail processes run in parallel (e.g. postfix
delivering several messages from the same series at once), two
processes can try to create a SeriesReference for the same msgid
simultaneously. The second one fails with an IntegrityError:
django.db.utils.IntegrityError: duplicate key value violates
unique constraint "patchwork_seriesreference_project_id_msgid_..."
DETAIL: Key (project_id, msgid)=(2, <...>) already exists.
This can result in incomplete series that never reach the
"received_all" state because the failed parsemail invocation
prevents one of the patches from being recorded.
The existing get/create pattern has a classic TOCTOU race: the get
succeeds (no reference found), but by the time create runs, another
process has already inserted the row. Replace both the try/get/
except/create block and the bare create call with get_or_create
which handles the race atomically at the database level.
Signed-off-by: Robin Jarry <robin@jarry.cc>
Reviwed-by: Stephen Finucane <stephen@that.guru>1 parent 66e9108 commit 3558907
2 files changed
Lines changed: 19 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1340 | 1340 | | |
1341 | 1341 | | |
1342 | 1342 | | |
1343 | | - | |
1344 | | - | |
1345 | | - | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
1357 | 1355 | | |
1358 | 1356 | | |
1359 | 1357 | | |
| |||
1440 | 1438 | | |
1441 | 1439 | | |
1442 | 1440 | | |
1443 | | - | |
1444 | | - | |
| 1441 | + | |
| 1442 | + | |
1445 | 1443 | | |
1446 | 1444 | | |
1447 | 1445 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments