-
Notifications
You must be signed in to change notification settings - Fork 215
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
Caching bug: Post content replaced by another post #839
Comments
Certainly looks caching-related. What's your cache backend? |
I’ll be able to dig in a bit later today, just wanted to get an issue in, in case others are hitting the same problem. |
Looks like the content is still there in the db. Updating one piece of content does seem to break its cache, but only its cache. However I'm not sure why the cache key would be the same for all the posts in a topic, that's next to figure out I guess. I can't reproduce locally so far.... |
Alonetone is on Dalli |
Running The caching logic is fairly custom and specific (vs. out of the box rails cache helpers in the view) so I guess it's not surprising that there may be edge cases. |
Here is how Thredded generates cache keys: thredded/lib/thredded/collection_to_strings_with_cache_renderer.rb Lines 30 to 32 in 9c4db86
This cache key should contain a fingerprint of the partial, the post ID, and the |
Going to close this for now, assuming there was some cross-version cache key issue. I'll reopen if we run into it again! |
This has recurred again and is making some of our threads unusable :/ It's only happened on one reply in the latest case: |
I'm going to try and track down if the problem is on writing or reading. Logically, the options are
|
Any news on this? We're running into the same problem. |
I've seen this issue before as well. But we don't have Thredded running in Prod yet. |
@fosterfarrell9 @andreibondarev Thanks for reporting. I never got around to completely untangling the caching logic, though I did do some preliminary logging/inspection of the code there. I think the next step is to find out how (what conditions) reliably reproduce the problem. Let me know if you have any ideas! |
I've also been seeing this pretty frequently lately around the same time I upgraded to Rails 6 (coincidentally, with also a couple thredded minor version bumps). I've got some time to dig in and try and diagnose what's going on, but I'm not sure where to start yet. @sudara I see you have three logical options of what might be causing it above; are those all still possibilities after your preliminary inspections, or are any more/less likely now? |
Could this possibly be related to the introduction of collection cache versioning which is default in Rails 6.0+? |
This may be needed as of rails/rails@4f2ac80 Refs #839
Use `combined_fragment_cache_key` instead of eagerly converting cache keys to strings. This may be slightly slower but is easier to maintain. Refs #839
Use `combined_fragment_cache_key` instead of the older methods. This may be slightly slower but is easier to maintain going forward. Refs #839
Use `combined_fragment_cache_key` instead of the older methods. This may be slightly slower but is easier to maintain going forward. Refs #839
Thanks @fosterfarrell9! If you're affected by this bug, please try #852 for a few days to see if it fixes the issue. |
(I also have #852 running in production and will report back if any users report the issue persists.) |
It looks like I'm still seeing the issue in production. At first I thought perhaps it was because I didn't manually bust any caches (and assumed some threads might still be affected if they were still cached), but I've already seen it a few times on new threads (since pushing it live). I'd be interested to see if things are fixed (or at least better) for others, though. I'll definitely give it more time while I keep digging in. |
I didn't bust cache on my deploy and see the issue post-deploy. I'll bust cache now and report if we see the issue recur. |
This may be needed as of rails/rails@4f2ac80 Refs #839
Use `combined_fragment_cache_key` instead of the older methods. This may be slightly slower but is easier to maintain going forward. Refs #839
Is everyone affected using dalli? Dalli is not tested with Rails 6 yet, does the issue disappear if you switch to Also finding out which one of the 3 things mentioned in #839 (comment) is happening would be very helpful for debugging the issue. |
https://github.com/sudara/alonetone/blob/master/config/environments/production.rb#L64 alonetone is using
The prerequisite to determining that is reproduction. The problem happens to us on production, but I haven't yet reproduced it on purpose. Has anyone else? I will dig back in with the goal to reproduce, but it would be helpful to understand more about the purpose of the custom caching code and why/what part of rails view caching wasn't enough. I'm not seeing any specs for The only place that calls the renderer is the |
Also, what's the reasoning for |
@sudara We want to render post contents with cache for multiple posts quickly, with a single call to get all the cached posts, and concurrent rendering of the uncached posts. We only want to cache post contents and not the other stuff around the post, such as the post actions because they are user-specific. With the methods Rails provides ouit-of-the-box, you either have to cache everything (not what we want), or cache the partials individually (no We render uncached posts using multiple threads because rendering can be slow, e.g. onebox rendering does network I/O. I always set some cache expiration on everything, so that the cache does not end up with unused data in it long term: the cache key is fingerprinted based on the partial's code, can change across Rails versions, etc. If the issue is visible in prod, perhaps you can inspect the contents of the production cache? Another thing to try is to make post rendering single-threaded like this: # config/initializers/thredded.rb
Thredded::CollectionToStringsWithCacheRenderer.render_threads = 1 |
I had a PM thread that I could reliably reproduce this on tonight (where every refresh showed a different comment repeated over and over in the thread, refreshing ~100 times without not seeing the bug). I set Just to make sure it wasn't a fluke related to the deploy, I set While a "hey it works for me!" isn't super useful, limiting the threads did indeed seem to accurately fix the issue for me in this instance, which might help a bit in the detective work of tracking down what's happening here. |
Gleb, thanks for the detail!
I'm almost tempted to look at whether the actions displaying in the UI could be managed with a bit of js sprinkles, allowing normal rails collection caching — but it sounds like there would still be some performance issue with onebox, etc... @drusepth Thanks for sharing!
That's interesting. It sounds like the issue is on read, assuming that cache isn't being broken or rewritten between refreshes.
Also super interesting. I wonder if the answer is in the difference between these two code branches: thredded/lib/thredded/collection_to_strings_with_cache_renderer.rb Lines 71 to 76 in 9c4db86
However, I'm still a bit confused by the |
Thanks for trying out Writing to cache and reading from it happens in a single thread. |
Reproduced locally in development mode |
The issue is indeed during rendering, not caching |
By the time we get to |
The |
Figured out the root cause and a solution |
v0.16.16 released with a fix! |
@glebm Just saw this!! Amazing, thanks! |
I'm experiencing this exact issue in Thredded 1.0.1. Could there have been a regression? |
@MakeSoftwareGreat I don't think it's exactly the same issue as this one, as the underlying problem was fixed by a very specific change (mutation of |
FYI Anyone still observing this issue, should not that another issue was solved which caused behaviour like this (now with tests) and has now been fixed in v1.1.0. |
Really strange (and bad!) bug here on Rails 6 with Thredded 0.16.13
I figured I would first open this issue in case others have ran into it, then investigate cause.
In some cases, it seems that every single post in a topic has its content replaced by a the last post.
Perhaps it’s caching related?
See: sudara/alonetone#780
The text was updated successfully, but these errors were encountered: