Skip to content

error connection to redis unix socket #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
davidka79 opened this issue Mar 9, 2020 · 5 comments · Fixed by #200
Closed

error connection to redis unix socket #187

davidka79 opened this issue Mar 9, 2020 · 5 comments · Fixed by #200

Comments

@davidka79
Copy link

davidka79 commented Mar 9, 2020

Hello
I would like to use only unix socket for redis connect, but when I try to do simple connection as in examples, I getting error:

2020/03/09 09:59:57 [error] 1878#1878: *18 lua entry thread aborted: runtime error: /opt/nginx/lualib/resty/redis.lua:141: bad argument #2 to 'connect' (number expected, got nil)
stack traceback:
coroutine 0:
[C]: in function 'connect'
/opt/nginx/lualib/resty/redis.lua:141: in function 'connect'
/opt/nginx/lualib/init.lua:29: in function </opt/pop/lualib/init.lua:23>, context: ngx.timer, client: 185.40.72.110, server: 0.0.0.0:443
2020/03/09 09:59:57 [error] 1878#1878: *19 lua entry thread aborted: runtime error: /opt/nginx/lualib/resty/redis.lua:141: bad argument #2 to 'connect' (number expected, got nil)

and my code is
in init_by_lua
--# LOGGING FUNCTION
function putLog(premature, customer)

-- redis connect
local redis = require "resty.redis"
local red = redis:new()
red:set_timeouts(1000, 1000, 1000)
local ok, err = red:connect("unix:/var/run/redis/redis.sock")

-- DB INSERT
red:select(0)
red:hincrby(customer, 'count', 1)

-- end, release connection back to pool
local ok, err = red:set_keepalive(10000, 100)
if not ok then
ngx.log(NGX.ERR, "failed to set keepalive: ", err)
return
end
end

log_by_lua_block {
local customer = tonumber(ngx.var.customer) or 0
local ok, err = ngx.timer.at(1, putLog, customer)
if not ok then
ngx.log(ngx.ERR, "ERROR from the CODE: failed to create timer: ", err)
end
}

OS:
Ubuntu Server 18.04.4
redis socket location:
/var/run/redis/redis.sock
srwxrw-rw- 1 redis redis 0 Feb 29 18:54 redis.sock

redis-cli and goland apps can connect to socket, I mean socket is present

Thank you
ADD:
If I use IP:Port instead of socket, everything is fine

UPD:
It does not mater socket is present or not, I getting this error even if I put wrong path to connection string :(

@walter0909
Copy link

when i use network config is true, use socket is false

@doujiang24
Copy link
Member

@davidka79
your sample should work according to the doc:
https://github.com/openresty/lua-resty-redis#connect

are you sure there is no other mistakes like a typo in your code?

bjoe2k4 added a commit to bjoe2k4/lua-resty-redis that referenced this issue May 30, 2020
The second argument of `sock:connect()` cannot be `nil`.
Fixes openresty#187
Bug introduced by 79d2421
@bjoe2k4
Copy link
Contributor

bjoe2k4 commented May 30, 2020

@doujiang24 Unfortunately, 79d2421 introduced a bug, which broke red:connect('unix:/some/redis.sock').
Sadly, none of the tests covers this. Tests 2&3 in bugs.t have the unix socket version commented out. I suggest to explicitly test this.

The connect method of a TCP socket sock = ngx.socket.tcp() does not accept nil as a second argument. Only the third argument may be nil.

@osmanmakal
Copy link

bad argument #2 port: number expected, got nil
stack traceback:
coroutine 0:
	[C]: in function 'error'
	/usr/local/openresty/lualib/resty/redis.lua:122: in function 'connect'

unix socket connection problem continues .. @bjoe2k4

@bjoe2k4
Copy link
Contributor

bjoe2k4 commented Jul 13, 2020

Have you tried my fix from the pull request? Waiting for my pull to be merged may take a while.

Unfortunately openresty devs are super busy these days and development (at least the public opensource part) is sometimes stalled for weeks, months and years. Nevertheless the openresty platform is one of the most stable platforms i have ever encountered and i am more than grateful to what i have learned by using it.

Also there is openresty/lua-nginx-module#1735 going on, which will likely require some changes on my side.

spacewander pushed a commit that referenced this issue Jul 16, 2020
The second argument of `sock:connect()` cannot be `nil`.
Fixes #187
Bug introduced by 79d2421
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants