Comments (11)
It should be easy to replicate this by lowering the connection timeout:
config set timeout 5
And then having a process that connects, sleeps for 6 seconds, and then tries to interact.
from wp-redis.
This is addressed by ee98d09 in #18
from wp-redis.
Actually, it might be addressed. If Redis throws a different exception message for timeout, then we'll need to catch that too.
from wp-redis.
@joshkoenig I'm having difficulty replicating the timeout exception.
Here's my test script:
salty-wordpress ➜ pantheon.dev cat test.php
<?php
global $wp_object_cache;
wp_cache_set( 'foo', 'bar' );
var_dump( $wp_object_cache->redis->isConnected() );
$wp_object_cache->cache = array();
var_dump( wp_cache_get( 'foo' ) );
sleep( 8 );
var_dump( $wp_object_cache->redis->isConnected() );
$wp_object_cache->cache = array();
var_dump( wp_cache_get( 'foo' ) );
$wp_object_cache->cache = array();
will reset the internal object cache, so it falls back to hitting Redis for the value.
Here's my test case:
salty-wordpress ➜ pantheon.dev redis-cli
127.0.0.1:6379> config set timeout 1
OK
127.0.0.1:6379> exit
salty-wordpress ➜ pantheon.dev wp eval-file test.php
bool(true)
string(3) "bar"
bool(true)
string(3) "bar"
I'd expect isConnected()
to return false in the second call.
We're also setting timeout=1
in __construct()
: https://github.com/pantheon-systems/wp-redis/blob/master/object-cache.php#L724
Is there something simple I'm doing wrong?
from wp-redis.
Oh. From the docs:
Timeouts are not to be considered very precise: Redis avoids to set timer events or to run O(N) algorithms in order to check idle clients, so the check is performed incrementally from time to time. This means that it is possible that while the timeout is set to 10 seconds, the client connection will be closed, for instance, after 12 seconds if many clients are connected at the same time.
from wp-redis.
I extended the script timeout to 20 seconds, and then killed the client connection with CLIENT KILL
:
salty-wordpress ➜ pantheon.dev redis-cli
127.0.0.1:6379> CLIENT LIST
addr=127.0.0.1:35639 fd=7 name= age=186 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
addr=127.0.0.1:35647 fd=5 name= age=4 idle=4 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=0 obl=0 oll=0 omem=0 events=r cmd=get
127.0.0.1:6379> CLIENT KILL 127.0.0.1:35647
OK
127.0.0.1:6379> CLIENT LIST
addr=127.0.0.1:35639 fd=7 name= age=195 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client
127.0.0.1:6379>
No dice. I think I'm going to punt on writing tests for this. If we can set up a way to reproduce on Pantheon, we can verify the Exception message to make sure we catch it and refresh the connection.
from wp-redis.
The isConnected()
method just tells if PHP "thinks" it's connected. I believe that just checks if a connection was established. The error case comes up when PHP believes this to be true, but turns out it's not true because the connection was closed from the server side.
I'll take a look at reproducing this again. The config set timeout
worked for me before, but I didn't turn it into a script.
from wp-redis.
I believe that just checks if a connection was established. The error case comes up when PHP believes this to be true, but turns out it's not true because the connection was closed from the server side.
Huh. That's pretty lame if true.
I suppose we could try a get()
or exists()
on an almost impossible value, and see if an exception is thrown.
Though, on the last line, wp_cache_get()
should've thrown an Exception if the connection was invalid. Maybe PhpRedis gracefully restarts the connection now if the connection details still work?
from wp-redis.
I don't think it gracefully restarts; the failure I was able to do before was to just so a get()
after waiting a while for things to timeout.
If you look at where the exception is thrown, it's when the socket communication isn't working no more:
https://github.com/phpredis/phpredis/blob/05e38d590143d044f18c63c5a581c645abd9d4b1/redis.c#L446
from wp-redis.
@joshkoenig how do you want to wrap this up?
from wp-redis.
I guess we'll close it for now given that we've added the handling for the error. Would feel better if we had a solid integration test. I'll make a new issue for this.
from wp-redis.
Related Issues (20)
- Implement `wp_cache_supports` function HOT 2
- many php warnings in my logs HOT 2
- CircleCI is not configured correctly HOT 4
- When `$wp_object_cache->is_redis_connected` is `false` there is a fatal error for `$missing_redis_message` HOT 4
- [BUGS-5944] Command "wp redis cli" fails HOT 1
- Fix some docblocks
- [BUGS-6118] PHP Deprecation notice on passing port = null @ Redis::connect() HOT 5
- As of WordPress 6.1 A Notice About Incorrect Support for `wp_cache_flush_runtime` HOT 8
- Re-add wordpress-upstream-tests to behat tests
- Fatal error in WP-CLI when accessing cache HOT 3
- esc_html is not safe to use (exception loop) HOT 3
- Implement PHPUnit and/or Behat tests for WP-CLI
- [BUGS-6318] file_exists(): open_basedir restriction in effect. HOT 9
- PHP 8.2 compatibility HOT 1
- [CMSP-467] Please don't strip all tags from the cache password. HOT 2
- [CMSP-470] Replace use of wp_strip_all_tags (possibly any wp filter function?) in object-cache.php
- Changes Merged from #360 Break Redis Connections on Pantheon Due to #400 and Incorrect array_replace_recursive call
- Large response size HOT 2
- [BUGS-6457] Warning when using tls protocol HOT 3
- PHP 8.1 deprecated warning
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wp-redis.