# Mogelijke Race Condition bij het bewerken van een bericht

**URL:** <https://meta.discourse.org/t/possible-race-condition-when-editing-a-post/177514>\
**Category:** Bug\
**Created:** [28 januari 2021 om 03:58 UTC](https://meta.discourse.org/t/possible-race-condition-when-editing-a-post/177514 "2021-01-28T03:58:29Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![concerto](https://avatars.discourse-cdn.com/v4/letter/c/dec6dc/32.png) [@concerto](https://meta.discourse.org/u/concerto)\
**Post date:** [28 januari 2021 om 03:58 UTC](https://meta.discourse.org/t/possible-race-condition-when-editing-a-post/177514/1 "2021-01-28T03:58:29Z")

</div>

## Problem

Concurrent edits to one wiki page can lead to unexpected behavior. In my case, the `quoted_posts` relationship between two post becomes wrong.

This may leads to other problems when `quoted_posts` is used, like in User#refresh\_avatar. The missing `quoted_posts` makes it unable to rebake all quoted posts.

## Possible Cause

The warning introduced by this [commit](https://github.com/discourse/discourse/commit/f60b10d090171c49134b20abcfb089ebb94fad21) is not enough to safeguard concurrent edit to a post, as the check is not atomic. This is a rare situation but it still can happen.

`PostRevisor#revise!` calls `QuotedPost.extract_from(@post)` , which delete all `quoted_posts` if there are no any quotes in a post. When two edit calls PostRevisor#revise! simultaneously, with one edit to add a quoted post and another to add a quoted post, the post content could end up with the edit that has quotes and the `quoted_post` relationship destroyed by the edit without any quotes.

## Possible Fix

Maybe we should consider acquiring a Redis lock when editing a post.

---

_[View the full topic](https://meta.discourse.org/t/possible-race-condition-when-editing-a-post/177514)._
