summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2022-01-26 17:55:30 -0800
committerGitHub <noreply@github.com>2022-01-26 17:55:30 -0800
commit0f8bb0fa0fdbef5348d2c82c2f27f529f916a02b (patch)
treed46dfb12c429cdd11dc1dea00048a2556c971fe4
parentbc7f8d8a7fc73a15e98bfb86a231602fca255fda (diff)
downloadrack-0f8bb0fa0fdbef5348d2c82c2f27f529f916a02b.tar.gz
Remove `rack.multithread`/`rack.multiprocess`/`rack.run_once`
These variables generally come too late to be useful. Make `Rack::Lock` always use a mutex. Co-authored-by: Samuel Williams <samuel.williams@oriontransfer.co.nz>
-rw-r--r--CHANGELOG.md4
-rw-r--r--SPEC.rdoc13
-rw-r--r--lib/rack.rb3
-rw-r--r--lib/rack/handler/cgi.rb3
-rw-r--r--lib/rack/handler/webrick.rb3
-rwxr-xr-xlib/rack/lint.rb19
-rw-r--r--lib/rack/lock.rb7
-rw-r--r--lib/rack/mock.rb3
-rw-r--r--lib/rack/request.rb1
-rw-r--r--lib/rack/session/pool.rb13
-rw-r--r--test/spec_lock.rb23
-rw-r--r--test/spec_session_pool.rb2
-rw-r--r--test/spec_webrick.rb3
13 files changed, 10 insertions, 87 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3ed7442d..67a0a27b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,10 @@ All notable changes to this project will be documented in this file. For info on
- Do not use semicolon as GET parameter separator. ([#1733](https://github.com/rack/rack/pull/1733), [@jeremyevans](https://github.com/jeremyevans))
+### Removed
+
+- Remove `rack.multithread`/`rack.multiprocess`/`rack.run_once`. These variables generally come too late to be useful. ([#1720](https://github.com/rack/rack/pull/1720), [@ioquatix](https://github.com/ioquatix), [@jeremyevans](https://github.com/jeremyevans)))
+
### Added
- `Rack::RewindableInput` supports size. ([@ahorek](https://github.com/ahorek))
diff --git a/SPEC.rdoc b/SPEC.rdoc
index c87cdb6e..6562b2ce 100644
--- a/SPEC.rdoc
+++ b/SPEC.rdoc
@@ -78,19 +78,6 @@ Rack-specific variables:
request URL.
<tt>rack.input</tt>:: See below, the input stream.
<tt>rack.errors</tt>:: See below, the error stream.
-<tt>rack.multithread</tt>:: true if the application object may be
- simultaneously invoked by another thread
- in the same process, false otherwise.
-<tt>rack.multiprocess</tt>:: true if an equivalent application object
- may be simultaneously invoked by another
- process, false otherwise.
-<tt>rack.run_once</tt>:: true if the server expects
- (but does not guarantee!) that the
- application will only be invoked this one
- time during the life of its containing
- process. Normally, this will only be true
- for a server based on CGI
- (or something similar).
<tt>rack.hijack?</tt>:: present and true if the server supports
connection hijacking. See below, hijacking.
<tt>rack.hijack</tt>:: an object responding to #call that must be
diff --git a/lib/rack.rb b/lib/rack.rb
index b931292e..ad3efec6 100644
--- a/lib/rack.rb
+++ b/lib/rack.rb
@@ -55,9 +55,6 @@ module Rack
RACK_SESSION = 'rack.session'
RACK_SESSION_OPTIONS = 'rack.session.options'
RACK_SHOWSTATUS_DETAIL = 'rack.showstatus.detail'
- RACK_MULTITHREAD = 'rack.multithread'
- RACK_MULTIPROCESS = 'rack.multiprocess'
- RACK_RUNONCE = 'rack.run_once'
RACK_URL_SCHEME = 'rack.url_scheme'
RACK_HIJACK = 'rack.hijack'
RACK_IS_HIJACK = 'rack.hijack?'
diff --git a/lib/rack/handler/cgi.rb b/lib/rack/handler/cgi.rb
index b514fe74..df0864a1 100644
--- a/lib/rack/handler/cgi.rb
+++ b/lib/rack/handler/cgi.rb
@@ -18,9 +18,6 @@ module Rack
RACK_VERSION => Rack::VERSION,
RACK_INPUT => Rack::RewindableInput.new($stdin),
RACK_ERRORS => $stderr,
- RACK_MULTITHREAD => false,
- RACK_MULTIPROCESS => true,
- RACK_RUNONCE => true,
RACK_URL_SCHEME => ["yes", "on", "1"].include?(ENV[HTTPS]) ? "https" : "http"
)
diff --git a/lib/rack/handler/webrick.rb b/lib/rack/handler/webrick.rb
index 07c7f9e0..9ce73b40 100644
--- a/lib/rack/handler/webrick.rb
+++ b/lib/rack/handler/webrick.rb
@@ -75,9 +75,6 @@ module Rack
RACK_VERSION => Rack::VERSION,
RACK_INPUT => rack_input,
RACK_ERRORS => $stderr,
- RACK_MULTITHREAD => true,
- RACK_MULTIPROCESS => false,
- RACK_RUNONCE => false,
RACK_URL_SCHEME => ["yes", "on", "1"].include?(env[HTTPS]) ? "https" : "http",
RACK_IS_HIJACK => true,
RACK_HIJACK => lambda { raise NotImplementedError, "only partial hijack is supported."},
diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb
index 0d3563b8..fe616138 100755
--- a/lib/rack/lint.rb
+++ b/lib/rack/lint.rb
@@ -166,22 +166,6 @@ module Rack
## <tt>rack.errors</tt>:: See below, the error stream.
- ## <tt>rack.multithread</tt>:: true if the application object may be
- ## simultaneously invoked by another thread
- ## in the same process, false otherwise.
-
- ## <tt>rack.multiprocess</tt>:: true if an equivalent application object
- ## may be simultaneously invoked by another
- ## process, false otherwise.
-
- ## <tt>rack.run_once</tt>:: true if the server expects
- ## (but does not guarantee!) that the
- ## application will only be invoked this one
- ## time during the life of its containing
- ## process. Normally, this will only be true
- ## for a server based on CGI
- ## (or something similar).
-
## <tt>rack.hijack?</tt>:: present and true if the server supports
## connection hijacking. See below, hijacking.
@@ -283,8 +267,7 @@ module Rack
##
%w[REQUEST_METHOD SERVER_NAME QUERY_STRING
- rack.version rack.input rack.errors
- rack.multithread rack.multiprocess rack.run_once].each { |header|
+ rack.version rack.input rack.errors].each { |header|
raise LintError, "env missing required key #{header}" unless env.include? header
}
diff --git a/lib/rack/lock.rb b/lib/rack/lock.rb
index 4bae3a90..3b084c28 100644
--- a/lib/rack/lock.rb
+++ b/lib/rack/lock.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require 'thread'
-
module Rack
# Rack::Lock locks every request inside a mutex, so that every request
# will effectively be executed synchronously.
@@ -12,10 +10,8 @@ module Rack
def call(env)
@mutex.lock
- @env = env
- @old_rack_multithread = env[RACK_MULTITHREAD]
begin
- response = @app.call(env.merge!(RACK_MULTITHREAD => false))
+ response = @app.call(env)
returned = response << BodyProxy.new(response.pop) { unlock }
ensure
unlock unless returned
@@ -26,7 +22,6 @@ module Rack
def unlock
@mutex.unlock
- @env[RACK_MULTITHREAD] = @old_rack_multithread
end
end
end
diff --git a/lib/rack/mock.rb b/lib/rack/mock.rb
index d9c8a9ce..c4f39b63 100644
--- a/lib/rack/mock.rb
+++ b/lib/rack/mock.rb
@@ -45,9 +45,6 @@ module Rack
RACK_VERSION => Rack::VERSION,
RACK_INPUT => StringIO.new,
RACK_ERRORS => StringIO.new,
- RACK_MULTITHREAD => true,
- RACK_MULTIPROCESS => true,
- RACK_RUNONCE => false,
}.freeze
def initialize(app)
diff --git a/lib/rack/request.rb b/lib/rack/request.rb
index 2df93ebd..1ac50087 100644
--- a/lib/rack/request.rb
+++ b/lib/rack/request.rb
@@ -172,7 +172,6 @@ module Rack
def content_length; get_header('CONTENT_LENGTH') end
def logger; get_header(RACK_LOGGER) end
def user_agent; get_header('HTTP_USER_AGENT') end
- def multithread?; get_header(RACK_MULTITHREAD) end
# the referer of the client
def referer; get_header('HTTP_REFERER') end
diff --git a/lib/rack/session/pool.rb b/lib/rack/session/pool.rb
index 849ac885..83a359fb 100644
--- a/lib/rack/session/pool.rb
+++ b/lib/rack/session/pool.rb
@@ -45,7 +45,7 @@ module Rack
end
def find_session(req, sid)
- with_lock(req) do
+ @mutex.synchronize do
unless sid and session = get_session_with_fallback(sid)
sid, session = generate_sid(use_mutex: false), {}
@pool.store sid.private_id, session
@@ -55,27 +55,20 @@ module Rack
end
def write_session(req, session_id, new_session, options)
- with_lock(req) do
+ @mutex.synchronize do
@pool.store session_id.private_id, new_session
session_id
end
end
def delete_session(req, session_id, options)
- with_lock(req) do
+ @mutex.synchronize do
@pool.delete(session_id.public_id)
@pool.delete(session_id.private_id)
generate_sid(use_mutex: false) unless options[:drop]
end
end
- def with_lock(req)
- @mutex.lock if req.multithread?
- yield
- ensure
- @mutex.unlock if @mutex.locked?
- end
-
private
def get_session_with_fallback(sid)
diff --git a/test/spec_lock.rb b/test/spec_lock.rb
index 89570498..c86d5b09 100644
--- a/test/spec_lock.rb
+++ b/test/spec_lock.rb
@@ -139,28 +139,6 @@ describe Rack::Lock do
lock.synchronized.must_equal false
end
- it "set multithread flag to false" do
- app = lock_app(lambda { |env|
- env['rack.multithread'].must_equal false
- [200, { "Content-Type" => "text/plain" }, %w{ a b c }]
- }, false)
- env = Rack::MockRequest.env_for("/")
- env['rack.multithread'].must_equal true
- _, _, body = app.call(env)
- body.close
- env['rack.multithread'].must_equal true
- end
-
- it "reset original multithread flag when exiting lock" do
- app = Class.new(Rack::Lock) {
- def call(env)
- env['rack.multithread'].must_equal true
- super
- end
- }.new(lambda { |env| [200, { "Content-Type" => "text/plain" }, %w{ a b c }] })
- Rack::Lint.new(app).call(Rack::MockRequest.env_for("/"))
- end
-
it 'not unlock if an error is raised before the mutex is locked' do
lock = Class.new do
def initialize() @unlocked = false end
@@ -181,7 +159,6 @@ describe Rack::Lock do
end
app = Rack::Lock.new lambda { |env| [200, { "Content-Type" => "text/plain" }, proxy.new(env)] }
response = app.call(Rack::MockRequest.env_for("/"))[2]
- response.env['rack.multithread'].must_equal false
end
it "unlock if an exception occurs before returning" do
diff --git a/test/spec_session_pool.rb b/test/spec_session_pool.rb
index e7ed3143..a8e1f3da 100644
--- a/test/spec_session_pool.rb
+++ b/test/spec_session_pool.rb
@@ -241,7 +241,7 @@ describe Rack::Session::Pool do
tnum = rand(7).to_i + 5
r = Array.new(tnum) do
Thread.new(treq) do |run|
- run.get('/', "HTTP_COOKIE" => cookie, 'rack.multithread' => true)
+ run.get('/', "HTTP_COOKIE" => cookie)
end
end.reverse.map{|t| t.run.join.value }
r.each do |resp|
diff --git a/test/spec_webrick.rb b/test/spec_webrick.rb
index d67dd35f..ffb03740 100644
--- a/test/spec_webrick.rb
+++ b/test/spec_webrick.rb
@@ -50,9 +50,6 @@ describe Rack::Handler::WEBrick do
it "have rack headers" do
GET("/test")
response["rack.version"].must_equal [1, 3]
- response["rack.multithread"].must_equal true
- assert_equal false, response["rack.multiprocess"]
- assert_equal false, response["rack.run_once"]
end
it "have CGI headers on GET" do