Page MenuHomePhabricator

RedisBagOStuff->incr broken by due to PHP serialization for primitives
Closed, ResolvedPublic

Description

This can be reproduced by running:

php /vagrant/mediawiki/tests/phpunit/phpunit.php --use-bagostuff=redis /vagrant/mediawiki/tests/phpunit/includes/objectcache/BagOStuffTest.php

on https://gerrit.wikimedia.org/r/#/c/91138/ .

I was able to eliminate the error by dropping RedisBagOStuff->incr (falling back on the parent's incr, lock, and unlock), but I'm not sure if that's an acceptable solution.

This breaks the ping limiter (tested), and probably a couple other things (not tested), when Redis is the main cache (as it is with MediaWiki-Vagrant).


Version: 1.22.0
Severity: normal
See Also:
https://bugzilla.wikimedia.org/show_bug.cgi?id=55987
https://bugzilla.wikimedia.org/show_bug.cgi?id=56069

Details

Reference
bz55986

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:22 AM
bzimport set Reference to bz55986.

The reason it doesn't work is that the value gets written as e.g. "i:0;", and Redis can't increment that.

I don't think this is a bug with MediaWiki, because the RedisBagOStuff class does not do any serializing. That is handled by the underlying phpredis library. Then again, I don't have much experience with Redis, so I could be wrong.

To clarify, by "This breaks", I mean master, not the proposed fix (using the parent's).

It's a bug with how MW uses Redis and the libraries. We specifically request to use the PHP serializer *and* use Redis's INCR call (which does the increment on the server, rather than the client sending the new value); that's the conflict.

See https://git.wikimedia.org/blob/mediawiki%2Fcore.git/d987f43b24a24a6f3fcd5886fedaf483fa3c6891/includes%2Fobjectcache%2FRedisBagOStuff.php#L58 and https://git.wikimedia.org/blob/mediawiki%2Fcore.git/d987f43b24a24a6f3fcd5886fedaf483fa3c6891/includes%2Fobjectcache%2FRedisBagOStuff.php#L297

Change 91296 had a related patch set uploaded by Mattflaschen:
Fix Redis increment behavior

https://gerrit.wikimedia.org/r/91296

Change 91296 merged by jenkins-bot:
Fix Redis increment behavior by using BagOStuff->incr instead

https://gerrit.wikimedia.org/r/91296