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

使用lua-resty-lock时的两个困惑 #20

Closed
bdjimmy opened this Issue Jun 5, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@bdjimmy
Copy link

bdjimmy commented Jun 5, 2018

hi,春哥
在项目当中用到lua-resty-lock, 有两个问题比较疑惑
1、如果需要两个锁的话,需要调用两次new方法,比如
local a_lock = resty_lock:new('my_locks')
a_lock:lock("a")
local b_lock = resty_lock:new('my_locks')
a_lock:lock("b")
不能向下面的方式操作
local locks= resty_lock:new('my_locks')
locks:lock("a")
locks:lock("b")

2、假如由于逻辑错误等lock成功后未调用unlock, 下次请求会被阻塞吗?
大致看了实现代码, new方法返回的table被回收时,会调用userdata自定义的gc方法, 可是lua的垃圾回收不是实时,这样在锁有效期内并且gc_lock未被调用的期间,就会造成所有请求都获取不到锁吧

@bdjimmy bdjimmy changed the title lua-resty-lock会导致死锁吗 使用lua-resty-lock时的两个困惑 Jun 5, 2018

@agentzh agentzh closed this in 6899e7b Jun 5, 2018

@agentzh

This comment has been minimized.

Copy link
Member

agentzh commented Jun 5, 2018

@bdjimmy Please, do not use Chinese here. This place is considered English only. If you really want to use Chinese, please join and post to the openresty (Chinese) mailing list instead. Please see https://openresty.org/en/community.html Thanks for your cooperation.

The dead lock thing is a known issue and we should always use lua-resty-core's FFI-based API instead. I've committed a patch to this library's master branch to enforce the use of lua-resty-core's resty.core.shdict module.

@agentzh

This comment has been minimized.

Copy link
Member

agentzh commented Jun 5, 2018

@bdjimmy And yes, a lock object corresponds to a single logical lock, naturally. You need separate lock objects for multiple locks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment