Created
September 30, 2012 12:51
-
-
Save gbelote/3806665 to your computer and use it in GitHub Desktop.
Fix NewRelic+Webrick memory leak
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ZThreadSweeper | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
pre_keys = Thread.current.keys | |
result = @app.call(env) | |
post_keys = Thread.current.keys | |
# nuke | |
post_keys.each { |k| Thread.current[k] = nil unless pre_keys.include?(k) } | |
result | |
end | |
end | |
Rails.configuration.middleware.insert_before 0, ZThreadSweeper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment