Unleash/unleash-client-php

Sporadic cache errors errors when reporting metrics

thedotedge opened this issue · 4 comments

Hi,
I have been experiencing sporadic errors in https://github.com/Unleash/unleash-client-php/blob/v1.2.074/src/Metrics/DefaultMetricsHandler.php#L40 while using https://packagist.org/packages/cache/redis-adapter as cache adapter:

TypeError · Return value of Unleash\Client\Metrics\DefaultMetricsHandler::getOrCreateBucket() must be an instance of Unleash\Client\Metrics\MetricsBucket, null returned

Metrics get reported regardless and are visible in Unleash, but this error persistently occurs without any specific pattern.

Hi, I fixed it in #31 but the underlying problem with your cache setup will still be there, it seems the cache implementation sometimes claims that the key is there and then doesn't return it. Do you perhaps have some kind of global default ttl? Is the Redis instance persistent? Couldn't it happen that the Redis server restarted mid request?

Thanks @RikudouSage, very impressive speed :)

I will test with a new version, otherwise:

  1. There's no global default TTL
  2. Redis is persistent and no restarts occurred for a while

getOrCreateBucket TypeError seems to be fixed in the latest tag, however, there's a similar error triggered in https://github.com/Unleash/unleash-client-php/blob/v1.2.174/src/Client/DefaultRegistrationService.php#L72 now.

TypeError · Return value of Unleash\Client\Client\DefaultRegistrationService::hasValidCacheRegistration() must be of the type bool, null returned

Ah, didn't think of it, tonight I'll check all the other places it could be in.