Skip to content

Commit 5d416b9

Browse files
committed
Deprecate config.threadsafe!
1 parent 2801786 commit 5d416b9

4 files changed

Lines changed: 20 additions & 22 deletions

File tree

guides/source/configuring.textile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ end
8787

8888
* +config.dependency_loading+ is a flag that allows you to disable constant autoloading setting it to false. It only has effect if +config.cache_classes+ is true, which it is by default in production mode. This flag is set to false by +config.threadsafe!+.
8989

90+
* +config.eager_load+ when true, eager loads all registered `config.eager_load_namespaces`. This includes your application, engines, Rails frameworks and any other registered namespace.
91+
92+
* +config.eager_load_namespaces+ registers namespaces that are eager loaded when +config.eager_load+ is true. All namespaces in the list must respond to the +eager_load!+ method.
93+
9094
* +config.eager_load_paths+ accepts an array of paths from which Rails will eager load on boot if cache classes is enabled. Defaults to every folder in the +app+ directory of the application.
9195

9296
* +config.encoding+ sets up the application-wide encoding. Defaults to UTF-8.
@@ -125,10 +129,6 @@ config.session_store :my_custom_store
125129

126130
This custom store must be defined as +ActionDispatch::Session::MyCustomStore+. In addition to symbols, they can also be objects implementing a certain API, like +ActiveRecord::SessionStore+, in which case no special namespace is required.
127131

128-
* +config.threadsafe!+ enables +cache_classes+ and +eager_load+ to make the application threadsafe.
129-
130-
WARNING: Threadsafe operation is incompatible with the normal workings of development mode Rails. In particular, automatic dependency loading and class reloading are automatically disabled when you call +config.threadsafe!+.
131-
132132
* +config.time_zone+ sets the default time zone for the application and enables time zone awareness for Active Record.
133133

134134
* +config.whiny_nils+ enables or disables warnings when a certain set of methods are invoked on +nil+ and it does not respond to them. Defaults to true in development and test environments.
@@ -746,13 +746,13 @@ The error occurred while evaluating nil.each
746746

747747
*+build_middleware_stack+* Builds the middleware stack for the application, returning an object which has a +call+ method which takes a Rack environment object for the request.
748748

749-
*+eager_load!+* If +config.cache_classes+ is true, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all the Ruby files from +config.eager_load_paths+.
749+
*+eager_load!+* If +config.eager_load+ is true, runs the +config.before_eager_load+ hooks and then calls +eager_load!+ which will load all +config.eager_load_namespaces+.
750750

751751
*+finisher_hook+* Provides a hook for after the initialization of process of the application is complete, as well as running all the +config.after_initialize+ blocks for the application, railties and engines.
752752

753753
*+set_routes_reloader+* Configures Action Dispatch to reload the routes file using +ActionDispatch::Callbacks.to_prepare+.
754754

755-
*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.cache_classes+ is set to true and +config.dependency_loading+ is set to false.
755+
*+disable_dependency_loading+* Disables the automatic dependency loading if the +config.eager_load+ is set to true.
756756

757757
h3. Database pooling
758758

railties/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
default_url_options[:script_name] to set proper application's mount point by
66
yourself. *Piotr Sarnacki*
77

8+
* `config.threadsafe!` is deprecated in favor of `config.eager_load` which provides a more fine grained control on what is eager loaded *José Valim*
9+
810
* The migration generator will now produce AddXXXToYYY/RemoveXXXFromYYY migrations with references statements, for instance
911

1012
rails g migration AddReferencesToProducts user:references supplier:references{polymorphic}

railties/lib/rails/application/configuration.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@ def paths
9090
end
9191
end
9292

93-
# Enable threaded mode. Allows concurrent requests to controller actions and
94-
# multiple database connections. Also disables automatic dependency loading
95-
# after boot, and disables reloading code on every request, as these are
96-
# fundamentally incompatible with thread safety.
9793
def threadsafe!
94+
ActiveSupport::Deprecation.warn "config.threadsafe! is deprecated. Rails applications " \
95+
"behave by default as thread safe in production as long as config.cache_classes and " \
96+
"config.eager_load are set to true"
9897
@cache_classes = true
9998
@eager_load = true
10099
self

railties/test/application/configuration_test.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -139,34 +139,31 @@ def teardown
139139
assert_instance_of Pathname, Rails.root
140140
end
141141

142-
test "marking the application as threadsafe sets the correct config variables" do
142+
test "initialize an eager loaded, cache classes app" do
143143
add_to_config <<-RUBY
144-
config.threadsafe!
144+
config.eager_load = true
145+
config.cache_classes = true
145146
RUBY
146147

147148
require "#{app_path}/config/application"
148-
assert AppTemplate::Application.config.cache_classes
149-
assert AppTemplate::Application.config.eager_load
149+
assert AppTemplate::Application.initialize!
150150
end
151151

152-
test "initialize a threadsafe app" do
153-
add_to_config <<-RUBY
154-
config.threadsafe!
155-
RUBY
156-
152+
test "application is always added to eager_load namespaces" do
157153
require "#{app_path}/config/application"
158-
assert AppTemplate::Application.initialize!
154+
assert AppTemplate::Application, AppTemplate::Application.config.eager_load_namespaces
159155
end
160156

161157
test "asset_path defaults to nil for application" do
162158
require "#{app_path}/config/environment"
163159
assert_equal nil, AppTemplate::Application.config.asset_path
164160
end
165161

166-
test "the application can be marked as threadsafe when there are no frameworks" do
162+
test "the application can be eager loaded even when there are no frameworks" do
167163
FileUtils.rm_rf("#{app_path}/config/environments")
168164
add_to_config <<-RUBY
169-
config.threadsafe!
165+
config.eager_load = true
166+
config.cache_classes = true
170167
RUBY
171168

172169
use_frameworks []

0 commit comments

Comments
 (0)