It would appear that MediaWiki doesn't detect edit conflicts when replica databases don't have the latest edit.
We've spent a lot of time recently testing the behavior of edit conflicts with DiscussionTools' reply tool (T252558), and noticing some cases where it appears to overwrite the previous edit when posting two comments very quickly:
- https://cs.wikipedia.beta.wmflabs.org/w/index.php?title=Diskuse_s_wikipedistou:RYasmeen_(WMF)&diff=2256&oldid=2255
- https://en.wikipedia.beta.wmflabs.org/w/index.php?title=Talk:T252558&diff=448708&oldid=448707
After convincing myself that our code is correct, I tried reproducing the problem using plain old wikitext editor and, lo and behold:
I was thinking it's because of replication lag because I could never reproduce this locally (where I don't have any replicas), and because we just went through a lot of pain due to other code loading data from replicas instead of master (T259855).
I went to read the code, and this looks obviously wrong:
public function internalAttemptSave( &$result, $markAsBot = false ) { ... # Load the page data from the master. If anything changes in the meantime, # we detect it by using page_latest like a token in a 1 try compare-and-swap. $this->page->loadPageData( 'fromdbmaster' ); $new = !$this->page->exists(); if ( $new ) { ... # Article exists. Check for edit conflict. $this->page->clear(); # Force reload of dates, etc. $timestamp = $this->page->getTimestamp(); $latest = $this->page->getLatest();
So we very carefully load the data from master before checking if the page already exists, and if it doesn't, we immediately clear that data and load it from the default source, which happens to be replicas.
I tried blaming but this code seems to have existed since times immemorial.