Skip to content

Commit 5ea766a

Browse files
authored
bugfix: connect to unix socket without opts table (#200)
The second argument of `sock:connect()` cannot be `nil`. Fixes #187 Bug introduced by 79d2421
1 parent e2db038 commit 5ea766a

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

lib/resty/redis.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,13 @@ function _M.connect(self, host, port_or_opts, opts)
140140
local ok, err
141141

142142
if unix then
143-
ok, err = sock:connect(host, port_or_opts)
144-
opts = port_or_opts
145-
143+
-- second argument of sock:connect() cannot be nil
144+
if port_or_opts ~= nil then
145+
ok, err = sock:connect(host, port_or_opts)
146+
opts = port_or_opts
147+
else
148+
ok, err = sock:connect(host)
149+
end
146150
else
147151
ok, err = sock:connect(host, port_or_opts, opts)
148152
end

t/ssl.t

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,49 @@ failed to connect: failed to do ssl handshake: 18: self signed certificate
244244
}
245245
--- response_body
246246
ok
247+
248+
249+
250+
=== TEST 6: non-ssl connection to unix socket (issue #187)
251+
--- config
252+
location /t {
253+
content_by_lua_block {
254+
local redis = require "resty.redis"
255+
local red = redis:new()
256+
257+
red:set_timeout(100)
258+
259+
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock")
260+
if not ok then
261+
ngx.say("failed to connect: ", err)
262+
return
263+
end
264+
265+
ngx.say("ok")
266+
}
267+
}
268+
--- response_body
269+
ok
270+
271+
272+
273+
=== TEST 7: non-ssl connection to unix socket with second argument nil (issue #187)
274+
--- config
275+
location /t {
276+
content_by_lua_block {
277+
local redis = require "resty.redis"
278+
local red = redis:new()
279+
280+
red:set_timeout(100)
281+
282+
local ok, err = red:connect("unix:$TEST_NGINX_HTML_DIR/nginx-ssl.sock",nil)
283+
if not ok then
284+
ngx.say("failed to connect: ", err)
285+
return
286+
end
287+
288+
ngx.say("ok")
289+
}
290+
}
291+
--- response_body
292+
ok

0 commit comments

Comments
 (0)