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

Stale data returned after delete call when key was already deleted #461

Open
dlh01 opened this issue Aug 21, 2024 · 0 comments
Open

Stale data returned after delete call when key was already deleted #461

dlh01 opened this issue Aug 21, 2024 · 0 comments

Comments

@dlh01
Copy link

dlh01 commented Aug 21, 2024

We recently encountered a scenario on a project where two simultaneous REST API calls updated post meta on the same post.

The updates themselves were saved to the database without an issue. However, we observed that when the slower of the two requests attempted to clear the post_meta cache for the post, the del request to Redis would fail. We assume it failed because the faster of the two requests had already deleted the same key after its post meta updates.

The slower of the two requests would then attempt to respond to the client with the updated list of post meta, but the response wouldn't include any of the newly saved post meta: After the del request failed, the subsequent call to _unset_internal() wouldn't be reached, and the stale "internal" data would be reused on the next call to get_post_meta():

wp-redis/object-cache.php

Lines 609 to 614 in 2fa07d3

if ( 1 !== $result ) {
return false;
}
}
$this->_unset_internal( $key, $group );

This scenario seems like it could be avoided by moving _unset_internal() to before the call to Redis, and making it unconditional. In our specific scenario, I think it would have prevented stale data from being returned to the client, assuming we diagnosed what happened accurately.

More generally, I think it would reflect the developer's intention more accurately because the deletion request would be reflected in at least one cache layer — the in-memory cache — even if the deletion wasn't reflected in Redis because there was an actual problem deleting the key there.

I'm happy to submit a PR if this suggestion seems sensible.

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

No branches or pull requests

1 participant