Sulu, strange hash related error when trying to save page / post?

406 Views Asked by At

Until recently everything was working well. Now, when I try to save (create or update) any page or post I get error message at top of the form "Error - There was an error when trying to save the form".

In error log I see this error:

“Uncaught PHP Exception Sulu\Component\Rest\Exception\InvalidHashException: “The given hash for the entity of type “Sulu\Bundle\ArticleBundle\Document\ArticleDocument” with the id “9e0720a7-5565-4a6f-a735-8a186b8fef9b” does not match the current hash. The entity has probably been edited in the mean time.” at /var/www/html/vendor/sulu/sulu/src/Sulu/Component/Hash/RequestHashChecker.php line 53"

Tried clearing symfony cache, website cache from admin, restarting docker containers.

I'm totally unaware that I did something to cause this error. Please help.

Update: strange thing I just noticed. When I try to save some article and I get that error and go back to overview page (where i.e. all articles of that type are listed) then I see unchanged article title. But when I click to edit it I see changed title?!? Like title on overview page and title on edit page are not used from the same place? How is that possible?

Update:

Now even I setup once more project from scratch saving articles causes that error. Some more info:

In stack trace last command executed is:

in vendor/elasticsearch/elasticsearch/src/Elasticsearch/ConnectionPool/StaticNoPingConnectionPool.php (line 64)

an it shoots out “No alive nodes found in your cluster”.

And while I'm setting up the project when executing:

php bin/console ongr:es:index:create

I get error:

{"error":{"root_cause":[{"type":"resource_already_exists_exception","reason  
  ":"index [su_articles/sWs5F1uzSFO8bFiZqF1Egw] already exists","index_uuid":  
  "sWs5F1uzSFO8bFiZqF1Egw","index":"su_articles"}],"type":"resource_already_e  
  xists_exception","reason":"index [su_articles/sWs5F1uzSFO8bFiZqF1Egw] alrea  
  dy exists","index_uuid":"sWs5F1uzSFO8bFiZqF1Egw","index":"su_articles"},"st  
  atus":400} 

And when I run:

php bin/console ongr:es:index:create --manager=live

I get similar:

In Connection.php line 675:
  {"error":{"root_cause":[{"type":"resource_already_exists_exception","reason":"index [su_articles_live/Pissm9ycRj-o79K4wrrD  
  AA] already exists","index_uuid":"Pissm9ycRj-o79K4wrrDAA","index":"su_articles_live"}],"type":"resource_already_exists_exc  
  eption","reason":"index [su_articles_live/Pissm9ycRj-o79K4wrrDAA] already exists","index_uuid":"Pissm9ycRj-o79K4wrrDAA","i  
  ndex":"su_articles_live"},"status":400} 

Also to mention that now saving pages works, but saving articles doesn't.

2

There are 2 best solutions below

0
On BEST ANSWER

This solved the issue on ElasticSearch index creation for me:

php bin/console ongr:es:index:drop --force
8
On

The error can happen in the following cases.

  • Expected Case somebody else did edit the same article like you and did save it
  • Unexpected Case your phpcr cache is not in sync
  • Unexpected Case you have a multi server setup but your cache.app is not configured to use a central cache

So if its one of the unexpected cases first you should clear your cache.pools with:

bin/console cache:pool:prune

If you have a multi server setup make sure you configure a central cache. Most use in this case a redis-server which you configure in your cache.yaml e.g.:

# config/packages/prod/cache.yaml
framework:
    cache:
        default_redis_provider: "%env(resolve:REDIS_DSN)%"
        app: cache.adapter.redis

Also make sure that you use the latest version and maybe update your phpcr cache configuration based on the sulu/skeleton: https://github.com/sulu/skeleton/blob/2.x/config/packages/prod/sulu_document_manager.yaml, there you could when performance doesn't matter in your case disable the phpcr cache, I would not recommend that.