Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing parent when deleting comment #8056

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jhass
Copy link
Member

@jhass jhass commented Sep 8, 2019

When a post is deleted, a comment retraction might race with a post retraction,
causing the comment deletion to raise because of a missing parent.

Fixes

NoMethodError: undefined method `update_comments_counter' for nil:NilClass
  from app/models/comment.rb:50:in `block in <class:Comment>'
  from lib/diaspora/federation/receive.rb:177:in `retraction'
  from config/initializers/diaspora_federation.rb:112:in `block (3 levels) in <top (required)>'
  from app/workers/receive_private.rb:13:in `block in perform'
  from app/workers/receive_base.rb:11:in `filter_errors_for_retry'
  from app/workers/receive_private.rb:10:in `perform'

Copy link
Member

@SuperTux88 SuperTux88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused, when does this happen? The stacktrace says it's failing here:

But deleting a comment would go here:

when Diaspora::Relayable
if object.root.author.local?
root_author = object.root.author.owner
retraction = Retraction.for(object)
retraction.defer_dispatch(root_author, false)
retraction.perform
else
object.destroy!
end

So do we receive a retraction for the post which then destroys all comments which then fails? If this fails, I would expect a bigger problem, because then probably no post with comment can't be deleted?

Or do we receive a rectraction for both, a comment and it's parent at the same time? But then I'm not sure if this really fixes it, or if it again fails later because deleting the parent also deletes all it's comment, so a comment can't be deleted twice?

app/models/comment.rb Outdated Show resolved Hide resolved
@jhass
Copy link
Member Author

jhass commented Oct 25, 2019

Well, honestly I don't know.

Or do we receive a rectraction for both, a comment and it's parent at the same time? But then I'm not sure if this really fixes it, or if it again fails later because deleting the parent also deletes all it's comment, so a comment can't be deleted twice?

Seems the more likely scenario to me and that the parent and comment retraction actually run at the same time, so this being a race condition, which is why earlier checks may pass.

Either way I could write a spec for this so this is a potential state the system can be in, right? We have no database constraints preventing this, so we should handle it IMO if for nothing but fault tolerance.

If it fails differently down the line again we'll get the next stacktrace and can handle it then :)

When a post is deleted, a comment retraction might race with a post retraction,
causing the comment deletion to raise because of a missing parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants