Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#48410 new defect (bug)

`wp_insert_post()` can result in duplicate post data

Reported by: henrywright's profile henry.wright Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

If 2 identical calls to wp_insert_post() are made close enough together, 2 posts are added to the database instead of 1. These posts differ by post ID only. The slug for example is the same.

This seems to happen because wp_insert_post() does a fair amount of processing before the database write takes place. The check to determine if a post already exists can be _stale_ at the point of insertion.

Change History (5)

#1 @davidbaumwald
5 years ago

  • Component changed from General to Posts, Post Types

#2 @davidbaumwald
5 years ago

@henrywright Thanks for the ticket! Can you provide a bit more background on the use-case in this instance where you're having some concurrency of post insertions? A code sample would be really helpful as well.

#3 @desrosj
5 years ago

  • Keywords reporter-feedback added

#4 @henry.wright
5 years ago

Sure @davidbaumwald

If a website user requests a post by visiting the post permalink and the post doesn't exist in our WordPress install, we send a request to an internal system to see if data is available to import. If data is available the internal system responds with the data and wp_insert_post() is called immediately after checking again if the post exists

The duplicate issue happens when we are under heavy load and wp_insert_post() is called with the same arguments in a short space of time

#5 @henry.wright
5 years ago

  • Keywords reporter-feedback removed
Note: See TracTickets for help on using tickets.