summary refs log tree commit
path: root/lib/rack/lock.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rack/lock.rb')
-rw-r--r--lib/rack/lock.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/rack/lock.rb b/lib/rack/lock.rb
index 923dca59..b5a41e8e 100644
--- a/lib/rack/lock.rb
+++ b/lib/rack/lock.rb
@@ -11,12 +11,21 @@ module Rack
 
     def call(env)
       @mutex.lock
+      @env = env
+      @old_rack_multithread = env[RACK_MULTITHREAD]
       begin
-        response = @app.call(env.merge(RACK_MULTITHREAD => false))
-        returned = response << BodyProxy.new(response.pop) { @mutex.unlock }
+        response = @app.call(env.merge!(RACK_MULTITHREAD => false))
+        returned = response << BodyProxy.new(response.pop) { unlock }
       ensure
-        @mutex.unlock unless returned
+        unlock unless returned
       end
     end
+
+    private
+
+    def unlock
+      @mutex.unlock
+      @env[RACK_MULTITHREAD] = @old_rack_multithread
+    end
   end
 end