Release the entire env

This commit is contained in:
Lin Jen-Shin 2018-02-07 22:44:05 +08:00
parent bbfce29ba8
commit 31f1ec59a7
4 changed files with 16 additions and 11 deletions

View File

@ -23,6 +23,6 @@ warmup do |app|
end
map ENV['RAILS_RELATIVE_URL_ROOT'] || "/" do
use Gitlab::ReleaseController
use Gitlab::Middleware::ReleaseEnv
run Gitlab::Application
end

View File

@ -1,9 +0,0 @@
module Gitlab
module Middleware
ReleaseController = Struct.new(:app) do
def call(env)
app.call(env).tap { env.delete('action_controller.instance') }
end
end
end
end

View File

@ -0,0 +1,14 @@
module Gitlab
module Middleware
# Some of middleware would hold env for no good reason even after the
# request had already been processed, and we could not garbage collect
# them due to this. Put this middleware as the first middleware so that
# it would clear the env after the request is done, allowing GC gets a
# chance to release memory for the last request.
ReleaseEnv = Struct.new(:app) do
def call(env)
app.call(env).tap { env.clear }
end
end
end
end

View File

@ -1,6 +1,6 @@
require 'spec_helper'
describe Gitlab::Middleware::ReleaseController do
describe Gitlab::Middleware::ReleaseEnv do
let(:inner_app) { double(:app) }
let(:app) { described_class.new(inner_app) }
let(:env) { { 'action_controller.instance' => 'something' } }