CacheInterface produces invalid results upon get()

Symfony version(s) affected: 4.4.19 and possibly more

Description
While using redis (via the extension) as cache the cached results are slightly… weird.
I’m unsure what exactly happens behind the scenes so I’ll assume that the metadata storage is somehow modyfing the underlying redis cached result.
What I mean is they appear as arrays, always.

a:1:{s:10:"\x9D\x90\xD9\x0F\x05\x00\x00\x00\x05_";i:36000;}

for example

While not a huge deal, as I really don’t care how they look like, we have gotten a weird result while getting results from cache sometimes.
For example the following code works around 99%% of the time:

return $this->cache->get('some_key', function (ItemInterface $item) {
    $item->expiresAt($time = new \DateTime('+1 hour'));

    return new Hit(['some data'], $time);
}

Where Hit is a class that takes mixed as it’s first parameter and DateTimeInterface as second (later stored as private properties).

We had the following error appear

Return value of Someclassr::getCachedData() must be an instance ofApp\Model\Cahce\Hit, array returned

With the following backtrace

{
  "file":"projectpath/vendor\/symfony\/cache\/LockRegistry.php",
  "line":99,
  "function":"Symfony\\Component\\Cache\\Adapter\\{closure}",
  "class":"Symfony\\Component\\Cache\\Adapter\\TraceableAdapter",
  "type":"-\u003E"
},
{
  "file":"projectpath/vendor\/symfony\/cache\/Traits\/ContractsTrait.php",
  "line":88,
  "function":"compute",
  "class":"Symfony\\Component\\Cache\\LockRegistry",
  "type":"::"
},
{
  "file":"projectpath/vendor\/symfony\/cache-contracts\/CacheTrait.php",
  "line":70,
  "function":"Symfony\\Component\\Cache\\Traits\\{closure}",
  "class":"Symfony\\Component\\Cache\\Adapter\\AbstractAdapter",
  "type":"-\u003E"
},
{
  "file":"projectpath/vendor\/symfony\/cache\/Traits\/ContractsTrait.php",
  "line":95,
  "function":"doGet",
  "class":"Symfony\\Component\\Cache\\Adapter\\AbstractAdapter",
  "type":"-\u003E"
},
{
  "file":"projectpath/vendor\/symfony\/cache-contracts\/CacheTrait.php",
  "line":33,
  "function":"doGet",
  "class":"Symfony\\Component\\Cache\\Adapter\\AbstractAdapter",
  "type":"-\u003E"
},
{
  "file":"projectpath/vendor\/symfony\/cache\/Adapter\/TraceableAdapter.php",
  "line":56,
  "function":"get",
  "class":"Symfony\\Component\\Cache\\Adapter\\AbstractAdapter",
  "type":"-\u003E"
},
{
  "file":"projectpath/src\/App\/Decorator\/CacheDecorator.php",
  "line":27,
  "function":"get",
  "class":"Symfony\\Component\\Cache\\Adapter\\TraceableAdapter",
  "type":"-\u003E"
},

While we do also have a cache decorator all it does is add a const to the name of each key (app version) and just calls the application cache

How to reproduce
I am unsure how to exactly reproduce this bug, as it seems to happen in some way where the application returns the incorrect data from cache.

Additional context
It seems like it doesn’t happen right away, we’re not quite able to pinpoint why exactly is this happening. I’ve also been unable to pinpoint what happens on my dev machine, we’ve only observed this bug in staging.

1 possible answer(s) on “CacheInterface produces invalid results upon get()

  1. @Nyholm Unsure. I’ve made the changes we talked about and it seems to be fine so far as my PM hasn’t reported new crashes for a while. So, possibly? Still, it’s a rather weird scenario.
    @nicolas-grekas Yeah that’s fair, thank you for your help.
    I’m still unsure what caused it to happen as the decorator for the service was extremely basic, but so far it seems fine?
    If we can reproduce this somehow later I’ll be sure to report it (without using a decorator).