Skip to content

Commit 1bb2084

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 16408c4 commit 1bb2084

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

lib/solid_queue/supervisor.rb

Lines changed: 6 additions & 2 deletions
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+
SolidQueue.logger.warn("No workers or dispatchers configured. Exiting...")
17+
end
1418
end
1519
end
1620

test/unit/async_supervisor_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ class AsyncSupervisorTest < ActiveSupport::TestCase
2828
assert_no_registered_processes
2929
end
3030

31+
test "start with empty configuration" do
32+
config_as_hash = { workers: [], dispatchers: [] }
33+
supervisor = run_supervisor_async(load_configuration_from: config_as_hash)
34+
35+
sleep(0.5)
36+
assert_no_registered_processes
37+
end
38+
3139
test "failed orphaned executions" do
3240
3.times { |i| StoreResultJob.set(queue: :new_queue).perform_later(i) }
3341
process = SolidQueue::Process.register(kind: "Worker", pid: 42, name: "worker-123")

test/unit/fork_supervisor_test.rb

Lines changed: 10 additions & 0 deletions
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)