We're getting this error message on our sites : Notice: unserialize(): Error at offset 0 of 2527853 bytes in _dmemcache_get_pieces() (line 329 of memcache/dmemcache.inc).

Our setup is :
two load balanced servers
one db server
pecl-memcached installed
memcache module installed
cache_consistent installed
site had large views (2.5mb+) where cache has to split values into 3 pieces

We didn't this on our dev servers which had one server for both web & db.

After some investigation, problem seemed to be that the $pieces array in _dmemcache_get_pieces() wasn't in the correct order. e.g. instead of 0,1,2 we have 1,0,2. So when the pieces were put back together, mangled data.

Added a ksort which resolved the issue. Patch attached.

Comments

jeremy’s picture

Priority: Normal » Major
Issue tags: +7.x-1.6-blocker

Thanks for the patch, tagging to be sure this is resolved in the next release.

tauseef.gill’s picture

thank you for the patch, It has resolved the issue on our sites.

jeremy’s picture

Status: Active » Needs review
StatusFileSize
new582 bytes

Thanks for reporting this. I've attached what should be a more correct patch, letting the PECL extension handle this. Testing would be appreciated.

sirnjeet’s picture

Tested patch, couldn't reproduce error. Thanks!

swaps’s picture

@jeremy : We faced the same issue . We were getting error " unserialize() [function.unserialize]: Error at offset 1048395 of 6028676 bytes in _dmemcache_get_pieces() "

This patch worked like charm !!

Thanks @jeremy.

searchmax’s picture

But why does this issue gets encountered? Is it due to large cached data in memcache or due to distributed server setups where there are multiple db servers with load balancers. This issue popped up on its own but unable to figure out on why this issue has popped up?

Thanks in advance for clarification.

swaps’s picture

@searchmax: For my case, environment setup is distributed server setup; but issue occurred when size increased for cached data in memcache.

jeremy’s picture

@searchmax, this can happen when you have multiple memcache servers, and you request an item that was large enough to be split into multiple pieces. This is because Memcached::getMulti doesn't guarantee the order in which the pieces will be returned, unless you set the Memcached::GET_PRESERVE_ORDER flag (which the attached patch fixes). So the answer to your question is "yes, both of those together".

  • Jeremy committed 3039461 on 7.x-1.x
    Issue #2415109 by Jeremy, sirnjeet: Fix unserialize() notice, enforce...
jeremy’s picture

Status: Needs review » Fixed

Thanks for everyone who tested. Committed to 7.x-1.x:
http://cgit.drupalcode.org/memcache/commit/?id=3039461

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jeremyattime’s picture

@jeremy: I've applied the patch (https://www.drupal.org/files/issues/2415109.patch) successfully, but now seeing a different issue:

PHP Fatal error: Cannot pass parameter 2 by reference in /sites/all/modules/contrib/memcache/dmemcache.inc on line 375
PHP Stack trace:
PHP 1. {main}() /usr/share/pear/drush/drush.php:0
PHP 2. drush_main() /usr/share/pear/drush/drush.php:16
PHP 3. _drush_bootstrap_and_dispatch() /usr/share/pear/drush/drush.php:61
PHP 4. drush_bootstrap_to_phase() /usr/share/pear/drush/drush.php:81
PHP 5. drush_bootstrap() /usr/share/pear/drush/includes/bootstrap.inc:308
PHP 6. _drush_bootstrap_drupal_full() /usr/share/pear/drush/includes/bootstrap.inc:185
PHP 7. drupal_bootstrap() /usr/share/pear/drush/includes/bootstrap.inc:930
PHP 8. _drupal_bootstrap_full() /site/includes/bootstrap.inc:2278
PHP 9. module_invoke_all() /site/includes/common.inc:5215
PHP 10. call_user_func_array() /site/includes/module.inc:895
PHP 11. context_init() /site/includes/module.inc:895
PHP 12. context_get_plugin() /sites/all/modules/contrib/context/context.module:168
PHP 13. context_conditions() /sites/all/modules/contrib/context/context.module:474
PHP 14. _context_registry() /sites/all/modules/contrib/context/context.module:499
PHP 15. context_cache_set() /sites/all/modules/contrib/context/context.module:521
PHP 16. cache_set() /sites/all/modules/contrib/context/context.module:344
PHP 17. MemCacheDrupal->set() /site/includes/cache.inc:136
PHP 18. MemCacheDrupal->wildcardFlushes() /sites/all/modules/contrib/memcache/memcache.inc:188
PHP 19. MemCacheDrupal->wildcards() /sites/all/modules/contrib/memcache/memcache.inc:330
PHP 20. dmemcache_get_multi() /sites/all/modules/contrib/memcache/memcache.inc:378
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Cannot pass parameter 2 by reference in /sites/all/modules/contrib/memcache/dmemcache.inc, line 375

josh waihi’s picture

Attached is a simple patch to fix the php warning issue committed to 7.x-1.x

jeremyattime’s picture

Thanks @Josh. The updated patch works on my local. Will continue testing on Dev.

damienmckenna’s picture

Version: 7.x-1.5 » 7.x-1.x-dev
Status: Closed (fixed) » Needs review

It seems this needs the follow-on patch?

zuernbernhard’s picture

Yes 2415109-memcache-7.x-1.x-fix-php-warning.patch did the job for me, no other file needed.

zuernbernhard’s picture

Status: Needs review » Reviewed & tested by the community

  • Jeremy committed 243c2f4 on 7.x-1.x authored by Josh Waihi
    Issue #2415109 by Josh Waihi: PHP Fatal error: Cannot pass parameter 2...
jeremy’s picture

Status: Reviewed & tested by the community » Fixed
jeremy’s picture

  • Jeremy committed 6355fe8 on 6.x-1.x authored by Josh Waihi
    Issue #2415109 by Josh Waihi: PHP Fatal error: Cannot pass parameter 2...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

Eduardo Alvarez’s picture

I'm experimenting still this issue when using PECL Memcache library.
I provide patch for fixing the ordering when using the other php memcache library, seems 8.x version already implements similar approach.

Eduardo Alvarez’s picture

Status: Closed (fixed) » Needs review
jeremy’s picture

Status: Needs review » Fixed

See http://cgit.drupalcode.org/memcache/commit/?id=6355fe8 -- this is handled by the memcache/memcached extension. It works fine in the latest release with the recommended memcache extension. The not-recommended memcached extension requires latest -dev.

  • Jeremy committed fc392db on 7.x-1.x authored by Eduardo Alvarez
    Issue #2415109 by Eduardo Alvarez, Jeremy: Notice: unserialize(): Error...
jeremy’s picture

Ouch, I stand corrected! While fixing the tests I realized you were absolutely correct. Thanks for the patch, committed!

  • Jeremy committed 0edef6f on 6.x-1.x authored by Eduardo Alvarez
    Issue #2415109 by Eduardo Alvarez, Jeremy: Notice: unserialize(): Error...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.