openresty / openresty/lua-resty-redis
attempt to send data on a closed socket
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 2k
- Forks
- 447
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 3
Description
local confRedis = {
host = "127.0.0.1",
port = "6379",
password = "Lp8^w#H$r43@",
timeout = 1000,
max_idle_timeout = 1000*600,
pool_size = 100
}
function connectRedis()
local rds, err = redis:new()
if not rds then
ngx.log(ngx.ERR, "redis error: ", err)
return nil
end
rds:set_timeouts(confRedis.timeout, confRedis.timeout, confRedis.timeout)
ok, err = rds:connect(confRedis.host, confRedis.port)
if not ok then
ngx.log(ngx.ERR, "redis connect error: ", err)
rds:close()
return nil
end
local res, err = rds:auth(confRedis.password)
if not res then
ngx.log(ngx.ERR, "failed to authenticate: ", err)
rds:close()
return nil
end
return rds
end
function closeRedis(red)
if not red then
return
end
local times, err = red:get_reused_times()
ngx.log(ngx.ERR, "tttttttttttt: ", times, ":", err)
local ok, err = red:set_keepalive(confRedis.pool_max_idle_time, confRedis.pool_size)
if not ok then
ngx.log(ngx.ERR, "close redis: ", err)
return
end
end
function getCertRedis(domain)
local pemKey = domain .. ":pem"
local keyKey = domain .. ":key"
local rds = connectRedis()
if rds == nil then
ngx.log(ngx.ERR, domain, ",", "redis connect nil")
return nil, nil
end
local pem, err = rds:get(pemKey)
if err ~= nil then
ngx.log(ngx.ERR, domain, ",", "get pem from redis nil", err)
return nil, nil
end
local key, err = rds:get(keyKey)
if err ~= nil then
ngx.log(ngx.ERR, domain, ",", "get key from redis nil", err)
return nil, nil
end
if pem == ngx.null or key == ngx.null then
closeRedis(rds)
return nil, nil
end
closeRedis(rds)
return pem, key
end
function setCertRedis(domain, pemData, keyData)
if domain == nil or pemData == nil or keyData == nil then
return false
end
local pemKey = domain .. ":pem"
local keyKey = domain .. ":key"
local rds = connectRedis()
if rds == nil then
return false
end
local ok, err = rds:set(pemKey, pemData)
if not ok then
ngx.log(ngx.ERR, domain, ",", "cache cert pem error,", err)
return false
end
local ok, err = rds:set(keyKey, keyData)
if not ok then
ngx.log(ngx.ERR, domain, ",", "cache cert key error,", err)
return false
end
closeRedis(rds)
return true
end
errlog:
2019/08/17 11:57:25 [error] 13260#0: 63910 attempt to send data on a closed socket: u:0000000000000000, c:0000000000000000, ft:0 eof:0, context: ssl_certificate_by_lua, client: 106.14.115.254, server: 0.0.0.0:443
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 with the connectRedis, closeRedis, getCertRedis, and setCertRedis functions shown in the report, focusing on the ssl_certificate_by_lua* error path and Redis connection reuse. No repository file or test is named; done means identifying why data reaches a closed socket and verifying a fix against this failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, redis
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100