openresty / openresty/lua-resty-redis
Lots of redis connection in time wait.
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 2k
- Forks
- 447
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 3
Description
Hi,
I have a code like this:
function _M.get_redis(config, host, port)
local red = redis:new()
red:set_keepalive(config.redis_keepalive_in_milliseconds, config.redis_pool_size)
logger.debug("GoJek-Auth", "Trying to conntect to Redis")
local ok, _, err = pcall(red.connect, red, host, port)
if not ok or err ~= nil then
ngx.log(ngx.ERR, err)
return nil, errors.ERR_REDIS_CONNECTION
else
return red, nil
end
end
-- another file
-- codes
--
--
local red, err = utils.get_redis(config, config.customer_token_redis_host, config.customer_token_redis_port)
if err then
logger.error("Auth", "could not connect to redis.")
_M.authServiceResponse(config, token)
red:close()
end
where pool size is 50 and timeout is 20k ms. But when I do this.. netstat -an | grep TIME_WAIT | grep 6379 | wc -l it yields 28k , and I get a lot of cannot assign address..
I have also enabled tcp_tw_reuse and tcp_tw_recycle .. Why is this happening ? Does red:close() return the connection to the pool ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the shown get_redis function, especially set_keepalive, connect, and close behavior in lua-resty-redis. Reproduce the TIME_WAIT and “cannot assign address” counts with the stated pool size and timeout, then compare the observed connection lifecycle with the documented pooling semantics. Done means explaining whether close returns connections to the pool and identifying the cause of the excessive TIME_WAIT sockets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, nginx, redis
- Domain
- backend, databases, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100