activejob-locking icon indicating copy to clipboard operation
activejob-locking copied to clipboard

Redis connections are left open

Open bkroeker opened this issue 5 years ago • 1 comments

My app experienced an explosion of redis connections after I started using this gem, which is a problem because the redis service I use has a connection cap. It seems that this gem never disconnects redis connections, nor does it use a redis connection pool. Redis connections are left open until their ruby objects are eventually garbage collected.

The easiest solution for me was to shim some disconnect code into the "unlock" method, since I was overriding the suo gem adapter anyway so I could specify a port and password (see https://github.com/cfis/activejob-locking/issues/3).

In this case the relevant code is:

module SuoLockingAdapterExtension
  def unlock
    super
    lock_manager.client.close
  end
end
ActiveJob::Locking::Adapters::SuoRedis.send :prepend, SuoLockingAdapterExtension

Not sure how you want to incorporate that into the gem, but the line of code would presumably be needed by all redis services. I just happen to be using Suo.

bkroeker avatar Sep 10 '19 00:09 bkroeker

(Quantitatively speaking, I was seeing 150+ open connections regularly. My redis service caps at 200, and I never have more than 10 jobs running simultaneously, which is rare.)

bkroeker avatar Sep 10 '19 00:09 bkroeker