Find file
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (27 sloc) 778 Bytes


Rack middleware that detect and handle memory leaks


Add this line to your application's Gemfile:

gem 'rack-leakin'

Then, if you are using Rails, simply add to initializer:

Rails.application.config.middleware.use Rack::Leakin

You can set threshold in kilobytes and the handler:

Rack::Leakin.threshold = 131072 # default, 128MB

For example, it may be useful to send exceptions to Airbrake:

Rack::Leakin.handler = lambda do |env, beginning, ending|
  Airbrake.notify \
    :error_message => "Memory leak detected, from #{beginning}KB to #{ending}KB",
    :error_class   => 'MemoryLeak',
    :parameters => {
      :request_uri => env['REQUEST_URI'],
      :method => env['REQUEST_METHOD']