Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/qless/worker/forking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def run

# Wait for any child to kick the bucket
pid, status = Process.wait2
# only care about processes we spawned
next unless @sandboxes[pid]

code, sig = status.exitstatus, status.stopsig
log((code == 0 ? :info : :warn),
"Worker process #{pid} died with #{code} from signal (#{sig})")
Expand Down
20 changes: 20 additions & 0 deletions spec/integration/workers/forking_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ def self.perform(job)
expect(words).to eq %w[ after_fork job job job ]
end

it 'handles forks in calling code' do
childs_pre_fork, childs_post_fork = nil, nil
run_worker_concurrently_with(worker) do
# wait until worker forked childs boot up
loop do
break if worker.children.size > 0
sleep 0.1
end
childs_pre_fork = worker.children
fork{ sleep 0.1};
# Make sure we don't spawn extra worker processes for the
# non worker child that just exited.
# How to test for this without making it
# tied to the implementation nor sleeping for an arbitrary amount of time?
sleep 1
childs_post_fork = worker.children
end
expect(childs_post_fork).to eq childs_pre_fork
end

context 'when a job times out', :uses_threads do
it 'fails the job with an error containing the job backtrace' do
pending('I do not think this is actually the desired behavior')
Expand Down