Page MenuHomePhabricator

Race condition during data export
Closed, ResolvedPublic5 Estimated Story Points

Description

Currently, the data export marks data sets as exported in a chunk. It does that by relying on the data set creation timestamp. If a donation payment is being confirmed by an external payment provider while the exporter is running, it may happen, that its data set is being marked as exported, although it never was. This race condition needs to be prevented.

During execution, the exporter selects data sets to be exported using several conditions (status, creation timestamp, export timestamp). After writing the export file, the exact same conditions are used for setting the export timestamp. If a data set gets confirmed by external payment providers during the process, the conditions are true for UPDATE, although they have not been true for data set selection.

Acceptance Criteria

  • Investigate how the export works.
  • Data set export is wrapped in a transaction might be a solution.

Notes

  • The described workflow only applies to donations. Other data set types are already marked on a per-data-set level.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
kai.nissen set the point value for this task to 5.
kai.nissen moved this task from Backlog to Sprint ready on the WMDE-Fundraising-Tech board.

I have investigated this issue. The race condition exists (if a payment notification comes in while SpendenDumper.php processes donations between lines 239 and 255).

Wrapping the donation export in a transaction (and adding FOR UPDATE in the SELECT statement) would solve the race condition, but would block the payment handler for the duration of the export (5-10 minutes during the campaign), which would lead to PHP timeouts and donations not being updated.

I've found a workaround by using a temporary table containing the IDs of the donations that are to be exported, but I'm not sure if this is the best solution. I've posted a question on StackOverflow to see if the community can come up with a better solution.