Skip to content

Commit 7a9fa9c

Browse files
piotrppintsized
authored andcommitted
Prevent pooling broken sentinel connections when connecting to slave
We don't know whether sentinel that we connected to works correctly, so we can't put its connection to pool if we got an error
1 parent 9c801ff commit 7a9fa9c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/resty/redis/connector.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,12 @@ function _M.connect_via_sentinel(self, params)
263263
else
264264
-- We want a slave
265265
local slaves, err = get_slaves(sentnl, master_name)
266-
sentnl:set_keepalive()
267-
268266
if not slaves then
269267
return nil, err
270268
end
271269

270+
sentnl:set_keepalive()
271+
272272
-- Put any slaves on 127.0.0.1 at the front
273273
tbl_sort(slaves, sort_by_localhost)
274274

@@ -282,9 +282,9 @@ function _M.connect_via_sentinel(self, params)
282282
local slave, err, previous_errors = self:try_hosts(slaves)
283283
if not slave then
284284
return nil, err, previous_errors
285-
else
286-
return slave
287285
end
286+
287+
return slave
288288
end
289289
end
290290

0 commit comments

Comments
 (0)