Skip to content

Commit 1ddb833

Browse files
committed
Try disconnecting before each fork made in the lib
1 parent c96ad6b commit 1ddb833

File tree

5 files changed

+9
-6
lines changed

5 files changed

+9
-6
lines changed

lib/puma/plugin/solid_queue.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def start(launcher)
1212
end
1313

1414
launcher.events.on_booted do
15-
@solid_queue_pid = fork do
15+
@solid_queue_pid = SolidQueue.safe_fork do
1616
Thread.new { monitor_puma }
1717
SolidQueue::Supervisor.start
1818
end

lib/solid_queue.rb

+5
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,10 @@ def instrument(channel, **options, &block)
7373
ActiveSupport::Notifications.instrument("#{channel}.solid_queue", **options, &block)
7474
end
7575

76+
def safe_fork(&block)
77+
Record.clear_all_connections!
78+
fork { block.call }
79+
end
80+
7681
ActiveSupport.run_load_hooks(:solid_queue, self)
7782
end

lib/solid_queue/supervisor.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ def start_process(configured_process)
8080
instance.mode = :fork
8181
end
8282

83-
Record.clear_all_connections!
84-
85-
pid = fork do
83+
pid = SolidQueue.safe_fork do
8684
process_instance.start
8785
end
8886

test/integration/puma/plugin_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class PluginTest < ActiveSupport::TestCase
1515
-s
1616
config.ru
1717
]
18-
@pid = fork do
18+
@pid = SolidQueue.safe_fork do
1919
exec(*cmd)
2020
end
2121
end

test/test_helpers/processes_test_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module ProcessesTestHelper
22
private
33

44
def run_supervisor_as_fork(**options)
5-
fork do
5+
SolidQueue.safe_fork do
66
SolidQueue::Supervisor.start(**options.with_defaults(skip_recurring: true))
77
end
88
end

0 commit comments

Comments
 (0)