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

Empty entities loaded from Redis second level cache #272

Closed
BourotBenjamin opened this issue May 25, 2016 · 6 comments
Closed

Empty entities loaded from Redis second level cache #272

BourotBenjamin opened this issue May 25, 2016 · 6 comments
Labels
doctrine Related to Doctrine integration

Comments

@BourotBenjamin
Copy link

BourotBenjamin commented May 25, 2016

We configured redis some weeks ago in our test environment and it was working fine.

Now we try to use it in our prod environment, we've got issues.
Sometimes, some of our users are empty and when we try to get informations, it crash our app.

Example :
When we call :

$user->getLanguage()->getLocale()

Symfony screams that getLanguage returns null (But the user have a language and without redis, it works fine)

There is the config :


snc_redis:
    # configure predis as client
    clients:
        doctrine:
            type: predis
            alias: cache_doctrine
            dsn: %cache_server_dsn%
    # configure doctrine caching
    doctrine:
        metadata_cache:
            client: cache_doctrine
            entity_manager: default
            document_manager: default
        result_cache:
            client: cache_doctrine
            entity_manager: default
            document_manager: default
            namespace: "dcrc:"
        query_cache:
            client: cache_doctrine
            entity_manager: default


services:
    snc_second_level_cache:
        class: %snc_redis.doctrine_cache.class%
        calls:
            - ["setRedis", ["@snc_redis.cache_doctrine"]]
            - ["setNamespace", ["DoctrineSecondLevelCache"]] 

doctrine:
    orm:
        entity_managers:
            default:
                metadata_cache_driver: redis
                query_cache_driver: redis
                result_cache_driver: redis
                second_level_cache:
                        region_cache_driver:
                             type: service
                             id: snc_second_level_cache
                        region_lock_lifetime: 60
                        log_enabled: true
                        region_lifetime: 3000
                        enabled: true
                        regions:
                            region_user:
                                lifetime: 3000
                                cache_driver:
                                    type: service
                                    id: snc_second_level_cache
                            region_language:
                                lifetime: 3000
                                cache_driver:
                                    type: service
                                    id: snc_second_level_cache

` 

On user :
`


/**
 * User
 *
 * @ORM\Table(name="users")
 * @ORM\Entity(repositoryClass="Acme\UserBundle\Entity\UserRepository")
 * @ORM\HasLifecycleCallbacks
 * @ExclusionPolicy("all")
 * @XmlRoot("User")
 * @ORM\AttributeOverrides({
 *      @ORM\AttributeOverride(name="usernameCanonical", column=@ORM\Column(type="string", name="username_canonical", length=255, unique=true, options={"collation"="utf8_bin"})),
 *      @ORM\AttributeOverride(name="emailCanonical", column=@ORM\Column(type="string", name="email_canonical", length=255, unique=true, options={"collation"="utf8_bin"})),
 * })
 * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="region_user")
 */

class User extends BaseUser
{


    /**
     * @ORM\ManyToOne(targetEntity="Language")
     * @ORM\JoinColumn(name="actual_lang_id", referencedColumnName="id")
     * @Expose
     * @Groups({"All"})  
     * @ORM\Cache(usage="NONSTRICT_READ_WRITE")
     */
    private $language;
`

I don't understand why my entities are empty, and when I clear the redis cache, the page can be loaded again. (And the problem would appear again in a few hours)

@lologhi
Copy link

lologhi commented Jan 25, 2017

Is this still pending? Have you found an alternative solution? (because I'd like to do it too)

@BourotBenjamin
Copy link
Author

I don't know if anyone does anything about it, but it seems not.
To avoid crashes, I've done this : doctrine/orm#6048 (event if it's a bad thing, blablabla ... -_-' )
I needed something working (even, less efficiently), and didn't had the time to fix symfony object hydrator (it seems the problem is here because the same crash happens with Memcache integration.

@insekticid
Copy link

insekticid commented Mar 6, 2018

it is very strange bug, somewhere between doctrine, redis bundle and redis.

tried

php bin/console cache:clear
php bin/console cache:pool:prune
rm -rf var/cache/dev
  • first page reload works
  • second reload has empty doctrine entity

I had to go to redis and call redis-cli flushall, but it is not sollution, because empty entity will appear very soon again :(

image

  • redis 4
  • symfony 4 (had this problem on symfony 3 too)
  • php 7.2 (had this problem on PHP 7.1 too)

edit 2018-03-07 - new debug info

image

@curry684 curry684 added the doctrine Related to Doctrine integration label Apr 7, 2018
@curry684
Copy link
Collaborator

curry684 commented May 8, 2018

If anyone is still having issues here - please remember that Doctrine Second Level Cache is currently marked experimental and may or may not work correctly in any environment.

From what I'm reading here I suspect there's no real issue on our end and it's just the cache itself occasionally borking up...?

@ghost
Copy link

ghost commented May 11, 2018

Having the same issue using APCU driver so it's not Redis specific.

@curry684
Copy link
Collaborator

Ok, thanks for confirming my suspicion there @vitalicwow. I'll close the issue here and consider it a Doctrine problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doctrine Related to Doctrine integration
Projects
None yet
Development

No branches or pull requests

4 participants