Skip to content

Commit 77374a3

Browse files
committed
bugfix: mark committed to false only when it is nil in conn
1 parent 449e8b4 commit 77374a3

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/resty/limit/conn.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ function _M.incoming(self, key, commit)
4646
local dict = self.dict
4747
local max = self.max
4848

49-
self.committed = false
49+
if self.committed == nil then
50+
self.committed = false
51+
end
5052

5153
local conn, err
5254
if commit then

t/conn.t

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,43 @@ failed to limit conn: rejected
285285
--- no_error_log
286286
[error]
287287
[lua]
288+
289+
290+
291+
=== TEST 6: incoming dry run shall not modify committed state
292+
--- http_config eval
293+
"
294+
$::HttpConfig
295+
296+
lua_shared_dict store 1m;
297+
"
298+
--- config
299+
location = /t {
300+
content_by_lua_block {
301+
local limit_conn = require "resty.limit.conn"
302+
local lim = limit_conn.new("store", 2, 1, 1)
303+
ngx.shared.store:flush_all()
304+
local key = "foo"
305+
306+
local delay, err = lim:incoming(key, true)
307+
if not delay then
308+
ngx.say("failed to limit conn: ", err)
309+
end
310+
delay, err = lim:incoming(key, false)
311+
if not delay then
312+
ngx.say("failed to limit conn: ", err)
313+
end
314+
if not lim:is_committed() then
315+
ngx.say("not committed")
316+
else
317+
ngx.say("committed")
318+
end
319+
}
320+
}
321+
--- request
322+
GET /t
323+
--- response_body
324+
committed
325+
--- no_error_log
326+
[error]
327+
[lua]

0 commit comments

Comments
 (0)