Automattic / jetpack

Security, performance, marketing, and design tools — Jetpack is made by WordPress experts to make WP sites safer and faster, and help you grow your traffic.
https://jetpack.com/
Other
1.57k stars 795 forks source link

Sync: Comments: Changing comment status several times seems to cause it to get stuck as approved on the shadow blog #11313

Open aerych opened 5 years ago

aerych commented 5 years ago

There seems to be a scenario where quickly changing the status of a comment can get it stuck as "approved" on the shadow blog. I think this would be related to Sync (apologies if I've added the wrong label).

I'm able to reproduce this on my test blog following these steps:

Steps to reproduce the issue

Have a Jetpack site and any other WordPress site. Ensure the Jetpack site is configured to accept pingbacks and the other site is configured to send them.

  1. Create a new post on the Jetpack site.
  2. On the other site, create a new post linking to the post on the Jetpack site and publish it to generate a ping back.
  3. Go back to the Jetpack site and find the ping back in wp-admin > comments.
  4. Change the status of the comment several times including from published to spam, from published to trashed, from trashed to restored. Leave its final state as pending. I'm not sure if there is a particular order or if just from published to trashed is the trigger.
  5. Go to the REST console and query for v1.1/sites/[your-jetpack-site-id]/comments/?context=edit&number=50&type=any&status=all and confirm that the returned result show the correct status.
  6. Append the force=wpcom param to the query and repeat: v1.1/sites/[your-jetpack-site-id]/comments/?context=edit&number=50&type=any&status=all&force=wpcom so that the query checks the wpcom shadow blog and does not pass through to the Jetpack site.
  7. Notice that the result does not have the correct status for the comment. In my tests it always shows approved instead of pending.

What I expected

The correct status to be returned by the query to the shadow blog

What happened instead

An incorrect status was returned.

I discovered this while researching an issue reported by Jetpack users of the wpios app. tl;dr: deleted comments were continuing to appear in the iOS app but not on the users's blog or in Calypso. The issue seems to be that the iOS app adds the force=wpcom parameter to the query in order to retrieve information about comment likes. See p4a5px-2l8-p2 for more info. We don't see this in Calypso because the force=wpcom query param is not used, although it seems like it should. This is an issue for users of the apps and would be very helpful if it could be resolved.

enejb commented 5 years ago

What is going on probably is that we ignore the same event if it happens multiple times.
So the data on the shadow site gets in the wrong state. Will investigate this futher.

Thanks for reporting the issue @aerych

aerych commented 5 years ago

Any new news on this one?

enejb commented 5 years ago

I did a bit more investigation here and it turns out that sending the same action (event and argument) when it comes to comments does result in the event not being processed.

There is a time limit of 5 minutes to this blocking. So what is happening is that if you toggle a comment from spam -> approved -> trashed -> approved for example will result (this is expected behavior right now) in the comment ending up in the trashed state. Since the 2 approved events are identical and the second gets ignored.

I think we should revisit some of the implementation here. cc: @lezama

stale[bot] commented 4 years ago

This issue has been marked as stale. This happened because:

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.