Issue #7720 has been updated by usa (Usaku NAKAMURA).

Status changed from Assigned to Rejected

1.9.3 is out of date

----------------------------------------
Backport #7720: Process.daemon does not clean up background Ruby threads, leading to hang at exit
https://bugs.ruby-lang.org/issues/7720#change-67438

* Author: benweint (Ben Weintraub)
* Status: Rejected
* Priority: Normal
* Assignee: usa (Usaku NAKAMURA)
----------------------------------------
Process.fork appears to make special considerations for Ruby background threads so that they are cleaned up in the child process after fork (since fork() only duplicates the calling thread). Process.daemon also relies on fork internally, but does not make the same considerations, leading to a hang at exit in a daemonized process that had multiple Ruby threads prior to calling Process.daemon.

The attached daemon.rb demonstrates the issue. It will call either Process.daemon (default) or Process.fork (if you pass 'fork' as the first arg).

If you pass nothing, causing it to call Process.daemon, the daemonized Ruby process will still think it has two threads, and will hang indefinitely on exit, in a loop in rb_thread_terminate_all. If you pass 'fork' as the first argument, the forked child does not hang, and appears to have only one Ruby thread (the one that called Process.fork).

It looks like rb_thread_atfork() is the relevant call in the fork case that makes this work, but it doesn't appear to be called in the daemon case.

---Files--------------------------------
daemon.rb (306 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>