From 5ddd115c8156975281b6961237a0fc94a104659d Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 20 Dec 2010 03:51:04 +0800 Subject: [PATCH] Rack::Lock should unlock if the app raises an exception. --- lib/rack/lock.rb | 3 +++ test/spec_lock.rb | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/rack/lock.rb b/lib/rack/lock.rb index 5cfc58d4d..bfc86dd81 100644 --- a/lib/rack/lock.rb +++ b/lib/rack/lock.rb @@ -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 diff --git a/test/spec_lock.rb b/test/spec_lock.rb index 43ad8e853..8386c5f22 100644 --- a/test/spec_lock.rb +++ b/test/spec_lock.rb @@ -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