ledgetech / lua-resty-redis-connector

Connection utilities for lua-resty-redis
234 stars 71 forks source link

rc = require("resty.redis.connector").new() get stack traceback #30

Closed caltonwu closed 4 years ago

caltonwu commented 5 years ago

6 function set_ngx_cache() 7 local rc = require("resty.redis.connector").new() 8 local sentinel, err = rc:connect { 9 url = "redis://172.16.1.21:26371", 10 url = "redis://172.16.1.31:26372", 11 url = "redis://172.16.1.32:26373" 12 } 13 local redis_monitor = 'zpredis' 14 assert(sentinel and not err, "sentinel should connect without errors") 15 16 local slaves, err = require("resty.redis.sentinel").get_slaves(sentinel,redis_monitor) 17 assert(slaves and not err, "slaves should be returned without error") 18 sentinel:close()

After running for a few hours, the following error occurred. [error] 19806#0: *143951211 lua entry thread aborted: runtime error: /usr/local/openresty/scripts/init.lua:14: sentinel should connect without errors stack traceback: coroutine 0: [C]: in function 'assert' /usr/local/openresty/scripts/init.lua:14: in function 'set_ngx_cache'

where is the problem?

hamishforbes commented 5 years ago

The problem is you're asserting that "sentinel should connect without errors", obviously in your environment sentinel does not connect without errors 100% of the time.

You should check the return value and do something, log the error, retry, whatever is appropriate.