fix user deletion race condition #320
Loading…
Reference in a new issue
No description provided.
Delete branch "user-deletion"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes the race condition described in https://github.com/misskey-dev/misskey/issues/7506.
The problem was that delivery attempts fetch the private key of the user being deleted from the database, however the record from the
user
table may be deleted before all delivery attempts are completed, cascade deleting the private key as well.There are a few different strategies for solving this:
user
record with this time delay. However, this approach can re-develop this same race condition under some circumstances, e.g. pausing the queue or otherwise delaying the scheduled execution of the delivery jobs, leading to the deletion job running before the delivery jobs.bullmq
, a modernized version ofbull
seems to have "flows", a kind of job dependance system).The exact approach here is basically (atomic) reference counting & garbage collecting the user record: Before delivery is started, the number of delivery attempts that will be started are stored in the
isDeleted
field. Each time a delivery job completes, terminally fails or is cleared from the queue, the value is decremented. Records that have reached 0 outstanding delivery attempts are picked up by the database cleanup job that deletes expired data.