openresty / lua-resty-redis

Lua redis client driver for the ngx_lua based on the cosocket API
1.9k stars 449 forks source link

Lua tcp socket read timed out #93

Open kushalkh opened 8 years ago

kushalkh commented 8 years ago

We see a lot of these errors in our nginx log file. Once in a while, the nginx server starts choking and stops serving the incoming request. We have to restart nginx servers to get them back live.

*41417426420 lua tcp socket read timed out

*41417426420 attempt to send data on a closed socket: u:0000000040267D38, c:0000000000000000, ft:0 eof:0

We have a redis connection in the code but i dont see any line number in the error so i doubt if it has something to do with redis. Thoughts?

Thanks

agentzh commented 8 years ago

@kushalkh You should handle any errors on the Lua land and configure the following line in your nginx.conf:

lua_socket_log_errors off;

See https://github.com/openresty/lua-nginx-module#lua_socket_log_errors

agentzh commented 8 years ago

@kushalkh The second error message is a clear indication that you didn't check return values of socket operations but continued using a closed socket object.

tangwz commented 7 years ago

I have a question same like this.

I use the https://github.com/pintsized/lua-resty-redis-connector to connect redis-sentinel. But I my connection closed and "attempt to receive data on a closed socket: u:0000000040631338, c:00007F822586FD40, ft:0 eof:1"

I just want know why my redis connectino closed? I use it read_reply in a while true loop like this:

while true do

    if wb.fatal then
        ngx.log(ngx.ERR, "websocket has disconnected:  ", err)
        return ngx.exit(444)
    end

    if ngx.worker.exiting() then
        return ngx.exit(444)
    end

    local res, err = red:read_reply()

    if not res then
        if err ~= "timeout" then
             ngx.log(ngx.ERR, "Redis read error: ", err)
             return ngx.exit(444)
        end
    else
        if check[res[3]] then
            local ok, err = pusher.ws_send(wb, "msg", res[4])
            if not ok then
                ngx.log(ngx.ERR, "failed to send text: ", err)
                return ngx.exit(444)
            end
        end
    end

end