jcasbin / redis-watcher

Redis watcher for jCasbin
https://github.com/casbin/jcasbin
Apache License 2.0
4 stars 11 forks source link

Redis sub exception occurs and sync becomes invalid #29

Closed yu-hailong closed 2 years ago

yu-hailong commented 2 years ago

I used redis-watcher for distribute sync. If I did not push message on provider about five minutes, and the following error happened, image

and , after the exception happened, even I did push message on provider, the following is not executed image

maybe it is relation with the redis-server settings image

casbin-bot commented 2 years ago

@tangyang9464 @imp2002

yu-hailong commented 2 years ago

Would you please help and give me some suggestion to avoid the problem, we find the problem on product - env. thanks a lot

yu-hailong commented 2 years ago

if exception happened ,should we "do while " and try to get a new jedis and subscibe again ??

image

yu-hailong commented 2 years ago
 @Override
    public void run() {
        while (true) {
            try (Jedis jedis = jedisPool.getResource()) {
                jedis.subscribe(subscriber, channel);
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

This change works for my local setup

imp2002 commented 2 years ago

It may be that server setting up the timeout not zero, it means after one period connection is disposed or closed. I'm not sure if a connect which is in subscribe will be closed by server, it's a guess.

Solution is set timeout on server to 0.

And Resubscribe is necessary, when an exception is thrown just like this or when redis is restart. Thank you for Issue and PR.