Skip to content

Commit

Permalink
Rack::Lock should unlock if the app raises an exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Firebaugh authored and josh committed Dec 19, 2010
1 parent 3bf8655 commit 5ddd115
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rack/lock.rb
Expand Up @@ -26,6 +26,9 @@ def call(env)
response = @app.call(env)
response[2] = Proxy.new(response[2], @mutex)
response
rescue Exception
@mutex.unlock
raise
ensure
env[FLAG] = old
end
Expand Down
8 changes: 8 additions & 0 deletions test/spec_lock.rb
Expand Up @@ -88,6 +88,14 @@ def close; @close_called = true; end
lock.synchronized.should.equal true
end

should "unlock if the app raises" do
lock = Lock.new
env = Rack::MockRequest.env_for("/")
app = Rack::Lock.new(lambda { raise Exception }, lock)
lambda { app.call(env) }.should.raise(Exception)
lock.synchronized.should.equal false
end

should "set multithread flag to false" do
app = Rack::Lock.new(lambda { |env|
env['rack.multithread'].should.equal false
Expand Down

0 comments on commit 5ddd115

Please sign in to comment.