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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bdragon’s picture

Status: Active » Needs review
FileSize
1.01 KB

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.

chx’s picture

FileSize
5.5 KB

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

chx’s picture

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

chx’s picture

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

Status: Needs review » Needs work

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

chx’s picture

Status: Needs work » Needs review
FileSize
4.91 KB

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

chx’s picture

FileSize
7.21 KB

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.

bdragon’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.29 KB

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.

webchick’s picture

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?

chx’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Needs review
FileSize
4.62 KB

Yes.

webchick’s picture

Issue tags: +Needs backport to D7

Tagging then.

bdragon’s picture

Issue tags: +project, +drupal.org D7

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

Senpai’s picture

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

bdragon’s picture

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'.

drumm’s picture

Issue tags: +8hr

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

drumm’s picture

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

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

chx’s picture

Assigned: chx » Unassigned
Issue summary: View changes

  • webchick committed 3dfe432 on 8.3.x
    Issue #1685170 by chx, bdragon: Fixed Possibility of {comment}.thread...

  • webchick committed 3dfe432 on 8.3.x
    Issue #1685170 by chx, bdragon: Fixed Possibility of {comment}.thread...

  • webchick committed 3dfe432 on 8.4.x
    Issue #1685170 by chx, bdragon: Fixed Possibility of {comment}.thread...

  • webchick committed 3dfe432 on 8.4.x
    Issue #1685170 by chx, bdragon: Fixed Possibility of {comment}.thread...

  • webchick committed 3dfe432 on 9.1.x
    Issue #1685170 by chx, bdragon: Fixed Possibility of {comment}.thread...