From 66982c7800730dc1ea62f17436226bdb46af6c4e Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 14 Jun 2018 12:49:30 +1000 Subject: [PATCH] FIX: stop using Rails connection reaper in multisite The Rails 5.2 connection reaper appears to be leaking threads this is a quick fix to stop it, though we need to make sure we never leak connection pools as well. --- config/application.rb | 4 ++++ lib/freedom_patches/reaper.rb | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lib/freedom_patches/reaper.rb diff --git a/config/application.rb b/config/application.rb index 4903811eb43..e360d84dcf8 100644 --- a/config/application.rb +++ b/config/application.rb @@ -270,5 +270,9 @@ module Discourse g.test_framework :rspec, fixture: false end + # we have a monkey_patch we need to require early... prior to connection + # init + require 'freedom_patches/reaper' + end end diff --git a/lib/freedom_patches/reaper.rb b/lib/freedom_patches/reaper.rb new file mode 100644 index 00000000000..c603ac70bbc --- /dev/null +++ b/lib/freedom_patches/reaper.rb @@ -0,0 +1,18 @@ +# Discourse ships with a connection reaper +# this patch ensures that the connection reaper never runs in Rails +# +# In Rails 5.2 the connection reaper is "per-pool" this means it can bloat +# threads quite a lot in a multisite +# +# Note, the "correct" way is to set this in the spec, however due to multisite +# getting reaper_interval=0 into all the specs is not going to be trivial +# when we eventually do that we can remove this patch + +if !defined? ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper + raise "Can not find connection Reaper class, this patch will no longer work!" +end + +class ActiveRecord::ConnectionAdapters::ConnectionPool::Reaper + def run + end +end