Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When you have a cache collector that has very long cache ID then the lock acquire can fail with an exception.
It was actually a weird migration of user roles that caused this for us, but if you have long user role machine names and a user has many roles then this could happen with the LocaleLookup.
Proposed resolution
Hash the lock name if it's > 255 characters. Or is the cache collector implementation responsible for generating a cache ID that's shorter? we actually allow cache ID's that are longer now and they're automatically hashed.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#10 | 2501191-10.patch | 4.81 KB | jhedstrom |
#8 | 2501191-08-TEST-ONLY.patch | 3.05 KB | jhedstrom |
Comments
Comment #1
BerdirNote: Until #2501183: LocaleLookup cache ID is using numeric indexes of the roles field, not role ID's is fixed, you actually need 100 roles or so for a user to trigger this ;) But it will be easier after that.
Comment #2
alexpottI think this is a major bug given that we have no limit on cid length.
Comment #3
jhedstromWe actually have a test now that is throwing this exception, but not failing. #2535774: Error handler swallows catchable fatal errors surfaces this failing.
Comment #4
jhedstromProbably not the best test in the world, but it illustrates the hidden exception.
Comment #5
jhedstromThis exception is actually not due to cid length, but rather to invalid characters. Hashing here would solve both length and characters.
Comment #6
catchComment #8
jhedstromThis adds a more appropriate integration test of the cache collector. I added a
@todo
because I'm not sure why a cache get would still work after the destruct method is called. This method is what writes to the semaphore table (by way of lock), so we want that in the test.Comment #10
jhedstromThis adds a cid/lock normalization method. It is copied directly from
DatabaseBackend
, and might make more sense as a static utility method somewhere.Comment #11
dawehnerNevermind my review ... you copied existing code from the cache backend, so both points are not valid.
IMHO we usually don't require to have mb enabled, right? I guess when mb is not enabled we could just go with the hash directly?
gg
Do we really need a cryptographic hash? Isn't it enough to go with something like sha512?
Comment #12
BerdirThere's an existing issue about mb_check_encoding() that results in completely broken sites without mbstring, so I actually that we shouldn't add it in more places until that's fixed.
If we move that code into a helper somewhere then we can discuss to refactor/fix that in the existing other issue but if not, then we should do it correctly i think.
Comment #14
dawehnerSee #2560123: mbstring_check_encoding() in cache database backend doesn't actually work ...
Comment #15
xjmLet's change this to assert a 200 instead. Asserting that there is no error text is not a reliable way to provide coverage as it can yield false positives.
Comment #16
effulgentsia CreditAttribution: effulgentsia at Acquia commentedDiscussed with @xjm, and we agree that fixing conditions that trigger exceptions is a great thing to do prior to release, so long as doing so isn't disruptive, which this doesn't appear to be.
Comment #17
jhedstromre #15: That test was mainly meant to illustrate the error existed (in our current tests, before tests for this issue were specifically added). I'll reroll to check for a 200.
Comment #18
jhedstromNevermind, the original error isn't caught by checking for a 200 (that's one reason it has remained hidden in our tests). It properly fails once #2535774: Error handler swallows catchable fatal errors is applied. We can either leave this explicit check for the error message, or remove it entirely since there are now explicit tests here?
(Setting to RTBC to get xjm's attention)
Comment #21
catchGiven this unblocks the error handler issue, committed/pushed to 8.0.x as is.
Let's improve the test coverage in the other issue though.