Hello there,
I know there are a lot of these questions/issues going around with this error, but I have gone through so many without finding any answer. Really hoping someone can help with this because it has been driving me mad for weeks.
I am doing something like this in a lua file (this is just the start of the file):
local redis = require "resty.redis"
local red = redis:new()
red:set_timeouts(500, 500, 500)
-- the method connect will try to use an already open connection from the pool
local ok, err = red:connect(os.getenv("REDIS_HOST"), 6379)
if not ok then
ngx.log(ngx.ERR, "failed to connect to redis: ", err)
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("HTTP_INTERNAL_SERVER_ERROR")
return ngx.exit(ngx.HTTP_OK)
end
-- lowercase string to full host + url
redirect_candidate = string.lower(ngx.var.host .. ngx.var.uri)
-- regex adds a trailing slash if missing
if not string.find(redirect_candidate, "/$") then redirect_candidate = redirect_candidate .. "/" end
-- ask Redis for the 301 redirect URL
rewrite_value, err = red:get(redirect_candidate)
if err then
ngx.log(ngx.ERR, "error during intial rewrite_value search: ", err)
ngx.status = ngx.HTTP_INTERNAL_SERVER_ERROR
ngx.say("HTTP_INTERNAL_SERVER_ERROR")
return ngx.exit(ngx.HTTP_OK)
end
After which all my transactions to redis are using `if err then` and then a similar pattern to 500.
However, I am still getting errors like: 2019/10/22 13:54:44 [error] 15#15: *1 attempt to send data on a closed socket: u:0000000000000000, c:0000000000000000, ft:0 eof:0, client: 172.19.0.1, server: _, request: "GET / HTTP/1.1", host: "www.**********.com"
If I do:
lua_socket_log_errors off
in the nginx.conf file then the errors go away, great I guess ;p But I am finding that gets to redis for keys are returning null when they do actually exist.
I am using:
red:set_timeouts(500, 500, 500)
and
local ok, err = red:set_keepalive(0, 100)
but just closing the socket instead of pooling still does not help.
Also, if I use `set_timeout(500)` instead of `set_timeouts(500, 500, 500)` these errors go away again, but the false nulls get returned still. (the get requests for particular sitepages work 99% of the time, but fail 1 or twice a day).
I can not figure out why on a homepage that should 301, I am occasionally unable to find it and I get a null value with no error. The only error I am seeing is the one above.
Also, should I really be using [[/$]] for regexes instead of ""?