Skip to content

Commit fc75fed

Browse files
authored
Merge pull request rails#50670 from byroot/active-support-after-fork-check
Get rid of `ForkTracker.check!`
2 parents df943c8 + a3d0530 commit fc75fed

File tree

4 files changed

+0
-51
lines changed

4 files changed

+0
-51
lines changed

activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ module ConnectionAdapters
5555
# about the model. The model needs to pass a connection specification name to the handler,
5656
# in order to look up the correct connection pool.
5757
class ConnectionHandler
58-
FINALIZER = lambda { |_| ActiveSupport::ForkTracker.check! }
59-
private_constant :FINALIZER
60-
6158
class StringConnectionName # :nodoc:
6259
attr_reader :name
6360

@@ -77,9 +74,6 @@ def current_preventing_writes
7774
def initialize
7875
# These caches are keyed by pool_config.connection_name (PoolConfig#connection_name).
7976
@connection_name_to_pool_manager = Concurrent::Map.new(initial_capacity: 2)
80-
81-
# Backup finalizer: if the forked child skipped Kernel#fork the early discard has not occurred
82-
ObjectSpace.define_finalizer self, FINALIZER
8377
end
8478

8579
def prevent_writes # :nodoc:

activerecord/lib/active_record/connection_adapters/pool_config.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ def connection_name
5050
end
5151

5252
def disconnect!(automatic_reconnect: false)
53-
ActiveSupport::ForkTracker.check!
54-
5553
return unless @pool
5654

5755
synchronize do
@@ -65,8 +63,6 @@ def disconnect!(automatic_reconnect: false)
6563
end
6664

6765
def pool
68-
ActiveSupport::ForkTracker.check!
69-
7066
@pool || synchronize { @pool ||= ConnectionAdapters::ConnectionPool.new(self) }
7167
end
7268

activesupport/lib/active_support/fork_tracker.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@ def after_fork_callback
2424
end
2525
end
2626

27-
if Process.respond_to?(:_fork) # Ruby 3.1+
28-
def check!
29-
# We trust the `_fork` callback
30-
end
31-
else
32-
alias_method :check!, :after_fork_callback
33-
end
34-
3527
def hook!
3628
::Process.singleton_class.prepend(CoreExt)
3729
end

activesupport/test/fork_tracker_test.rb

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -152,39 +152,6 @@ def test_kernel_fork_without_block
152152
ActiveSupport::ForkTracker.unregister(handler)
153153
end
154154

155-
def test_check
156-
count = 0
157-
handler = ActiveSupport::ForkTracker.after_fork { count += 1 }
158-
159-
assert_no_difference -> { count } do
160-
3.times { ActiveSupport::ForkTracker.check! }
161-
end
162-
163-
if Process.respond_to?(:_fork)
164-
Process.stub(:pid, Process.pid + 1) do
165-
assert_no_difference -> { count } do
166-
3.times { ActiveSupport::ForkTracker.check! }
167-
end
168-
169-
assert_no_difference -> { count } do
170-
3.times { ActiveSupport::ForkTracker.check! }
171-
end
172-
end
173-
else
174-
Process.stub(:pid, Process.pid + 1) do
175-
assert_difference -> { count }, +1 do
176-
3.times { ActiveSupport::ForkTracker.check! }
177-
end
178-
end
179-
180-
assert_difference -> { count }, +1 do
181-
3.times { ActiveSupport::ForkTracker.check! }
182-
end
183-
end
184-
ensure
185-
ActiveSupport::ForkTracker.unregister(handler)
186-
end
187-
188155
def test_basic_object_with_kernel_fork
189156
read, write = IO.pipe
190157
called = false

0 commit comments

Comments
 (0)