Skip to content

Commit 418f885

Browse files
committed
Don't try to start a supervisor on an empty configuration
It leads to weird errors, especially when forking, such as `Errno::ECHILD` when trying to check on the children status without having forked any children. I want to improve this with a generic configuration validation step, that would check this and other things, and abort/raise if there are any problems, but this will do for now.
1 parent b9b41db commit 418f885

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/solid_queue/supervisor.rb

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ def start(mode: :fork, load_configuration_from: nil)
99
SolidQueue.supervisor = true
1010
configuration = Configuration.new(mode: mode, load_from: load_configuration_from)
1111

12-
klass = mode == :fork ? ForkSupervisor : AsyncSupervisor
13-
klass.new(configuration).tap(&:start)
12+
if configuration.configured_processes.any?
13+
klass = mode == :fork ? ForkSupervisor : AsyncSupervisor
14+
klass.new(configuration).tap(&:start)
15+
else
16+
abort "No workers or processed configured. Exiting..."
17+
end
1418
end
1519
end
1620

test/unit/fork_supervisor_test.rb

+10
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ class ForkSupervisorTest < ActiveSupport::TestCase
4141
assert_no_registered_processes
4242
end
4343

44+
test "start with empty configuration" do
45+
config_as_hash = { workers: [], dispatchers: [] }
46+
47+
pid = run_supervisor_as_fork(load_configuration_from: config_as_hash)
48+
sleep(0.5)
49+
assert_no_registered_processes
50+
51+
assert_not process_exists?(pid)
52+
end
53+
4454
test "create and delete pidfile" do
4555
assert_not File.exist?(@pidfile)
4656

0 commit comments

Comments
 (0)