{"action":"created","issue":{"url":"https://api.github.com/repos/dv/redis-semaphore/issues/18","repository_url":"https://api.github.com/repos/dv/redis-semaphore","labels_url":"https://api.github.com/repos/dv/redis-semaphore/issues/18/labels{/name}","comments_url":"https://api.github.com/repos/dv/redis-semaphore/issues/18/comments","events_url":"https://api.github.com/repos/dv/redis-semaphore/issues/18/events","html_url":"https://github.com/dv/redis-semaphore/issues/18","id":24059606,"number":18,"title":"Deadlock when reusing redis connection","user":{"login":"stephankaag","id":6944,"avatar_url":"https://avatars.githubusercontent.com/u/6944?v=3","gravatar_id":"","url":"https://api.github.com/users/stephankaag","html_url":"https://github.com/stephankaag","followers_url":"https://api.github.com/users/stephankaag/followers","following_url":"https://api.github.com/users/stephankaag/following{/other_user}","gists_url":"https://api.github.com/users/stephankaag/gists{/gist_id}","starred_url":"https://api.github.com/users/stephankaag/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stephankaag/subscriptions","organizations_url":"https://api.github.com/users/stephankaag/orgs","repos_url":"https://api.github.com/users/stephankaag/repos","events_url":"https://api.github.com/users/stephankaag/events{/privacy}","received_events_url":"https://api.github.com/users/stephankaag/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2013-12-10T19:32:03Z","updated_at":"2016-04-17T10:22:09Z","closed_at":null,"body":"Works:\r\n\r\n      i = 0\r\n      threads = [1, 2].collect do\r\n        Thread.new do\r\n          Redis::Semaphore.new(\"foo\", :redis => Redis.new(:db => 15)).lock do\r\n            i += 1\r\n          end\r\n        end\r\n      end\r\n      threads.each &:join\r\n      i.should == 2\r\n\r\nDeadlocks:\r\n\r\n      i = 0\r\n      threads = [1, 2].collect do\r\n        Thread.new do\r\n          Redis::Semaphore.new(\"foo\", :redis => @redis).lock do\r\n            i += 1\r\n          end\r\n        end\r\n      end\r\n      threads.each &:join\r\n      i.should == 2\r\n"},"comment":{"url":"https://api.github.com/repos/dv/redis-semaphore/issues/comments/210993202","html_url":"https://github.com/dv/redis-semaphore/issues/18#issuecomment-210993202","issue_url":"https://api.github.com/repos/dv/redis-semaphore/issues/18","id":210993202,"user":{"login":"dv","id":44360,"avatar_url":"https://avatars.githubusercontent.com/u/44360?v=3","gravatar_id":"","url":"https://api.github.com/users/dv","html_url":"https://github.com/dv","followers_url":"https://api.github.com/users/dv/followers","following_url":"https://api.github.com/users/dv/following{/other_user}","gists_url":"https://api.github.com/users/dv/gists{/gist_id}","starred_url":"https://api.github.com/users/dv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dv/subscriptions","organizations_url":"https://api.github.com/users/dv/orgs","repos_url":"https://api.github.com/users/dv/repos","events_url":"https://api.github.com/users/dv/events{/privacy}","received_events_url":"https://api.github.com/users/dv/received_events","type":"User","site_admin":false},"created_at":"2016-04-17T10:22:09Z","updated_at":"2016-04-17T10:22:09Z","body":"I agree, due to the blocking nature of some usecases of `redis-semaphore`, reusing redis clients should be discouraged. Since even adding a Ruby mutex to the blocking code in redis-semaphore would not cover all possible \"abuses\"*, for now I won't add code to support this use-case.\r\n\r\nI'll add a README part that explains it and warns against it. Also, it's still possible as long as you yourself take care \r\n\r\n*: It would only cover the use case where the redis client is only used by redis-semaphore. As soon as other code also uses it the Ruby mutex will be useless."}}