mperham / connection_pool

Generic connection pooling for Ruby
MIT License
1.63k stars 143 forks source link

Nested checkout in same Thread yields same connection #65

Closed arnodirlam closed 9 years ago

arnodirlam commented 9 years ago

I'm using sidekiq and connection_pool. I was trying to get two Redis connections from one pool in a single thread, one pipelined, one not. I expected to get two different connections using this code example:

Sidekiq.redis do |conn|
  conn.pipelined do
    Sidekiq.redis do |conn2|
      # expect conn != conn2
    end
  end
end

However, it's the same connection, so everything I do with conn2 naturally is pipelined as well. Is there a way to get two different connections from one pool in a single thread? If not, would that be something you'd consider or accept a pull request for?

mperham commented 9 years ago

That's not the semantic connection_pool provides (and it wouldn't work with Redis since you can't have two operations running in parallel on different connections, Redis is single-threaded). Your scenario would allow a single thread to exhaust the pool with, e.g., a poorly written recursive function.