Replying to deleted comment causes major database error

Created on 25 March 2020, over 5 years ago
Updated 29 July 2025, 19 days ago

We have a site with frequent comments posted using the Ajax Comments module. Recently, a comment was deleted by a moderator at the same time a user was replying to the comment. More specifically, the user clicked the "reply" link, started typing the message, and by the time the user clicked "Save", the moderator had removed the comment to which the reply was being written.

This caused a major database malfunction, where a comment record was saved to the comment table with comment threading, but pid = 0. Every comment added after this one displayed a nasty Ajax 200 error message to users, and entity exception errors to the database. The only way to fix the problem was reset the broken pid to the original comment id (cid) value, and the delete the reply comment from the system.

The attached patch fixes this problem by adding another validation step. When ajax_comments_preview_js or ajax_comments_submit_js functions are run, it checks once again if the comment being replied to still exists, and if it does not, it removes the original comment and comment form, and displays an error message.

Please review, thanks.

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States ron_s

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Your patch for the Ajax Comments module effectively addresses a critical database malfunction caused by simultaneous comment deletion and reply attempts. By re-validating the existence of the parent comment within ajax_comments_preview_js and ajax_comments_submit_js, you've introduced a crucial safeguard. This prevents the creation of orphaned comment records (pid = 0) and the subsequent cascading errors that previously necessitated manual database intervention. The proposed solution of removing the form and displaying an error message provides a clean and user-friendly way to handle this race condition.

  • Your patch for the Ajax Comments module effectively addresses a critical database malfunction caused by simultaneous comment deletion and reply attempts. By re-validating the existence of the parent comment within ajax_comments_preview_js and ajax_comments_submit_js, you've introduced a crucial safeguard. This prevents the creation of orphaned comment records (pid = 0) and the subsequent cascading errors that previously necessitated manual database intervention. The proposed solution of removing the form and displaying an error message provides a clean and user-friendly way to handle this race condition.

  • Your patch effectively addresses the issue by adding a validation step to check if the parent comment still exists before allowing a reply to be submitted. This prevents broken thread structures and database errors caused by replies to deleted comments. Milestone Mastercard For full reliability, consider also adding a server-side validation during comment submission to ensure replies to deleted comments are blocked even if the AJAX layer is bypassed

  • The proposed patch for the Ajax Comments module addresses a critical database malfunction that occurred when a user replied to a comment that was simultaneously being deleted by a moderator. The core issue was that a reply comment was being saved with a pid (parent ID) of 0, leading to a cascade of errors for all subsequent comments. The patch adds a crucial validation step within the ajax_comments_preview_js and ajax_comments_submit_js functions. This new check verifies the existence of the parent comment just before the reply is submitted. If the parent comment is no longer found, the patch removes the comment form and displays MyCardStatement an error message, effectively preventing the database corruption from happening. This is a solid solution that prevents a race condition from causing a major site-wide issue.

Production build 0.71.5 2024