Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #425 from SamSaffron/master

Fixed Rack::Lock so it correctly releases mutexes on throw
  • Loading branch information...
commit ea7ed1aeb8e6e0e5d68edca03a9d2e687a3ce388 2 parents d084a14 + 5c230ff
@rkh rkh authored
Showing with 12 additions and 5 deletions.
  1. +3 −4 lib/rack/lock.rb
  2. +9 −1 test/spec_lock.rb
View
7 lib/rack/lock.rb
@@ -13,12 +13,11 @@ def call(env)
old, env[FLAG] = env[FLAG], false
@mutex.lock
response = @app.call(env)
- response[2] = BodyProxy.new(response[2]) { @mutex.unlock }
+ body = BodyProxy.new(response[2]) { @mutex.unlock }
+ response[2] = body
response
- rescue Exception
- @mutex.unlock
- raise
ensure
+ @mutex.unlock unless body
env[FLAG] = old
end
end
View
10 test/spec_lock.rb
@@ -134,11 +134,19 @@ def close; @close_called = true; end
should "unlock if the app raises" do
lock = Lock.new
env = Rack::MockRequest.env_for("/")
- app = lock_app(lambda { raise Exception })
+ app = lock_app(lambda { raise Exception }, lock)
lambda { app.call(env) }.should.raise(Exception)
lock.synchronized.should.equal false
end
+ should "unlock if the app throws" do
+ lock = Lock.new
+ env = Rack::MockRequest.env_for("/")
+ app = lock_app(lambda {|env| throw :bacon }, lock)
+ lambda { app.call(env) }.should.throw(:bacon)
+ lock.synchronized.should.equal false
+ end
+
should "set multithread flag to false" do
app = lock_app(lambda { |env|
env['rack.multithread'].should.equal false
Please sign in to comment.
Something went wrong with that request. Please try again.