Download & Extend

Possibility of {comment}.thread duplication in the same node

Project:Drupal core
Version:7.x-dev
Component:comment.module
Category:bug report
Priority:normal
Assigned:chx
Status:needs work
Issue tags:needs backport to D7

Issue Summary

While analyzing issues on drupal.org, I detected that it is possible for multiple comments on a node to have the same {comment}.thread value.

To ensure data integrity, we should have a unique index on (nid, thread).

Drupal.org had 34 instances where duplication had happened. Most of this apparently happened at times where things were especially flaky. (I manually repaired the damage already.)

Detecting duplicate thread values:
(d6 naming, use 'comment' for a d7+ db)
select distinct l.nid from comments l, comments r WHERE l.nid = r.nid and l.thread = r.thread and l.cid < r.cid;

This takes 5 minutes to run on drupal.org slave.

Comments

#1

Status:active» needs review

Here's a patch to add the unique key.

It's probably faster to attempt to add the key and error out than it is to search for problems.

Whether this is acceptable or not, I don't know.

AttachmentSizeStatusTest resultOperations
1685170-thread-integrity.patch1.01 KBIdlePASSED: [[SimpleTest]]: [MySQL] 37,262 pass(es).View details | Re-test

#2

Doing that will abort the write and lose the comment. Not a good idea IMO.

AttachmentSizeStatusTest resultOperations
1685170_2.patch5.5 KBIdleFAILED: [[SimpleTest]]: [MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details..View details | Re-test

#3

Here's the diff -b for easier review. Also, D7.

AttachmentSizeStatusTest resultOperations
1685170_3.txt3.81 KBIgnored: Check issue status.NoneNone
1685170_3-d7-do-not-test.patch6.15 KBIgnored: Check issue status.NoneNone

#4

Assigned to:bdragon» chx

Well, that made it easier for me to spot the wrong prefix setting.

AttachmentSizeStatusTest resultOperations
1685170_4-d7-do-not-test.patch6.15 KBIgnored: Check issue status.NoneNone
1685170_4.patch5.5 KBIdleFAILED: [[SimpleTest]]: [MySQL] 39,757 pass(es), 8 fail(s), and 0 exception(s).View details | Re-test
1685170_4b-do-not-test.patch4.17 KBIgnored: Check issue status.NoneNone

#5

Status:needs review» needs work

The last submitted patch, 1685170_4.patch, failed testing.

#6

Status:needs work» needs review

Weird. All the comment tests passed for me. Let's then see without the function removal.

AttachmentSizeStatusTest resultOperations
1685170_6.patch4.91 KBIdlePASSED: [[SimpleTest]]: [MySQL] 39,764 pass(es).View details | Re-test

#12

We had a bunch of bot flukes but we are seemingly back on track. So here's a much more complete version, with lots more comment, lock_release and all that.

AttachmentSizeStatusTest resultOperations
1685170_7.patch7.21 KBIdlePASSED: [[SimpleTest]]: [MySQL] 39,760 pass(es).View details | Re-test

#13

Status:needs review» reviewed & tested by the community

Tested against postgresql and mysql using tsung.

Here's the configuration I used.

With the patch in I was unable to cause a duplicate.

Without the patch, I was getting a large percentage of duplicates -- some were even 3-way dupes.

AttachmentSizeStatusTest resultOperations
tsung.xml_.txt2.29 KBIgnored: Check issue status.NoneNone

#14

Status:reviewed & tested by the community» fixed

This felt like something we should add tests for, but chx explained that it's catching a race condition and we don't have a good way for testing for those. Thanks for the pointer to Tsung; never heard of that before!

Anyway, this looks fairly sane. It's adding checks for locking around this code and failing if they're encountered.

Committed and pushed to 8.x. Not sure if we should backport this to D7 too?

#15

Version:8.x-dev» 7.x-dev
Status:fixed» needs review

Yes.

AttachmentSizeStatusTest resultOperations
1685170_15.patch4.62 KBIdlePASSED: [[SimpleTest]]: [MySQL] 39,371 pass(es).View details | Re-test

#16

Tagging then.

#17

Issue tags:+Drupal.org D7, +project

More tagging -- this is important for the drupal.org d7 upgrade.

#18

Assigning to @bdragon for review of @chx's patch in #15

#19

Status:needs review» needs work

I'm getting duplicates during testing even after applying #15.

Also, typo in comment
+ // We need a lopp here to avoid race conditions: if another process
-- should be 'loop' instead of 'lopp'.

#20

Issue tags:+8hr

Adding an estimate for closing this out and/or mitigating it on Drupal.org.

#21

Issue tags:-8hr, -Drupal.org D7, -project

This has been mitigated for Drupal.org: #1944448: Drupal.org D7 deployment. We'll run a query to check for duplicates before proceeding.

nobody click here