0
0
Fork 0

Refactoring: Move rack middleware (#34140)

This commit is contained in:
David Roetzel 2025-03-11 16:24:06 +01:00 committed by GitHub
parent 6d5a1fbe1d
commit 9041ce3c18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 90 additions and 82 deletions

View file

@ -0,0 +1,34 @@
# frozen_string_literal: true
module Mastodon
module Middleware
class SocketCleanup
def initialize(app)
@app = app
end
def call(env)
@app.call(env)
ensure
clean_up_sockets!
end
private
def clean_up_sockets!
clean_up_redis_socket!
clean_up_statsd_socket!
end
def clean_up_redis_socket!
RedisConnection.pool.checkin if Thread.current[:redis]
Thread.current[:redis] = nil
end
def clean_up_statsd_socket!
Thread.current[:statsd_socket]&.close
Thread.current[:statsd_socket] = nil
end
end
end
end