/usr/lib/ruby/vendor_ruby/rack/lock.rb is in ruby-rack 1.6.4-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | require 'thread'
require 'rack/body_proxy'
module Rack
# Rack::Lock locks every request inside a mutex, so that every request
# will effectively be executed synchronously.
class Lock
FLAG = 'rack.multithread'.freeze
def initialize(app, mutex = Mutex.new)
@app, @mutex = app, mutex
end
def call(env)
old, env[FLAG] = env[FLAG], false
@mutex.lock
response = @app.call(env)
body = BodyProxy.new(response[2]) { @mutex.unlock }
response[2] = body
response
ensure
@mutex.unlock unless body
env[FLAG] = old
end
end
end
|