Concurrency issue with comment threading

Description

When creating a new comment, threaded_left and threaded_right are supposed to be adjusted to accommodate the new comments. However, if two replies are being added to the same comment at exactly the same time, both new comments will end up with the same threaded_left and threaded_right values. This is because CommentsController#create loads the commentable (i.e. the parent comment) outside of the transaction, and it's not reloaded inside the transaction, so its threaded_left and threaded_right values (which are used to compute the new comments' threaded_left and threaded_right values) are out-of-date when the second comment is saved.

Currently, threaded_left and threaded_right are only used to compute the number of descendants that a given comment had (children_count), which is only displayed when the max depth has been reached and the comments are hidden. So on top of being tricky to replicate thanks to concurrency, it's almost impossible to notice.

Testing Instructions: This is basically impossible to replicate, so I'm not sure it can be tested manually. But it would be good to try replying to some comments and make sure that it still works as expected.

Assignee

Unassigned

Reporter

ticking instant

Roadmap

Comments

Priority

Low

Affects versions

Fix versions

None

Components

BackEnd

Difficulty

Medium

Milestone

Internal 0.9
Configure