Open sada opened 4 months ago
Thank you for the report. I am not sure why you would want to use at_exit in such a scenario, but also I currently cannot follow on why the first child should not exit in this case? Do I understand correctly, that your proposed solution is to replace exit if pid == safefork
by exit! if pid == safefork
?
exit! if pid == safefork
Yes. I thought I should stop the first child process so that it is not affected by anything else.
I am not sure why you would want to use at_exit in such a scenario, but also I currently cannot follow on why the first child should not exit in this case?
This issue occurs with delayed_job and debug. Increase the number of workers using delayed_job's number_of_workers option.
https://github.com/collectiveidea/delayed_job/blob/v4.1.11/lib/delayed/command.rb#L102-L105
Next, loaded debug.
https://github.com/ruby/debug/blob/v1.9.2/lib/debug/local.rb#L106-L107
delayed_job tries to increase the number of workers, but the child process is not stopped, just like the repro program. Also, in Rails development, debug is loaded by default, When starting delayed_job, unexpected block is caused by this issue.
Your environment
ruby -v
: ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]Describe the bug
Calling Process.waitpid inside the at_exit method will prevent the child process from stopping.
To Reproduce
Script:
Gemfile
test_daemon.rb
Terminal:
Child process doesn't stop.
The following fork operations are no longer possible.
https://github.com/thuehlinger/daemons/blob/a0e84bcebe8b872ff59e1e0aa10e1f1718a933b1/lib/daemons.rb#L43-L51
By the way, I encountered this problem when using delayed_job and debug.
Expected behavior
Child processes can be stopped. Since the first child process should be stopped, I thought it would be a good idea to change the call to the exit! method.
https://github.com/thuehlinger/daemons/blob/a0e84bcebe8b872ff59e1e0aa10e1f1718a933b1/lib/daemons/daemonize.rb#L67