ASKBOT / askbot-devel

Askbot is a Django/Python Q&A forum. **Contributors README**: https://github.com/ASKBOT/askbot-devel#how-to-contribute. Commercial hosting of Askbot and support are available at https://askbot.com
Other
1.56k stars 626 forks source link

Race condition in instant notification sending. #328

Open geekofalltrades opened 9 years ago

geekofalltrades commented 9 years ago

I might be wrong about this, because this particular code path is obfuscated under so much old, half-transitioned legacy junk, but the sending of instant update notification emails seems to create a race condition.

On Post save, the post_updated signal is received by record_post_update_activity in models.__init__, which then queues a celery task, record_post_update_celery_task. record_post_update_celery_task calls Post.get_updated_activity_data, which may call Post.get_latest_revision... which just returns the most recently created PostRevision object for the Post in question.

What if record_post_update_celery_task gets queued, then another revision is created before it has a chance to run? When it eventually calls Post.get_latest_revision, it will be working with the wrong PostRevision object.

evgenyfadeev commented 9 years ago

This might lead to incorrect content of notification email - a potential issue albeit not critical. Nobody yet reported of this taking place. It can happen if queue is slow or by rare coincidence or at very high rate of edits.

Low priority for now, but worth thinking of a fix. Perhaps making code a bit more clean in the respect that you've mentioned in the comment above is more worthwhile at the moment.