Project

General

Profile

Actions

Bug #18497

closed

Fiber内でProcess.daemonをするとSegmentation faultが起こる

Added by sevenc-nanashi (Nanashi. @sevenc-nanashi) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [aarch64-linux]
[ruby-dev:51146]

Description

ruby -e 'Fiber.new { Process.daemon true, true }.resume'

OCIのUbuntu(ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [aarch64-linux])で確認出来ましたが、WSL(ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [x86_64-linux])では確認出来ませんでした。


Files

sf.log (17 KB) sf.log sevenc-nanashi (Nanashi. @sevenc-nanashi), 01/19/2022 08:10 AM
Actions #1

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Backport changed from 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED
Actions #2

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|d650b17686d49c2ce8e6a87039861154e93d4621.


rb_fiber_terminate must not return [Bug #18497]

In a forked process from a fiber, the fiber becomes the only
fiber, fiber_switch does nothing as there is no other fibers,
rb_fiber_terminate does not terminate the fiber. In that case,
reaches the end of fiber_entry finaly, which is declared as
"COROUTINE" and should never return.

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

In 2.7 or earlier, bf3b2a43741e or the following patch is also needed.

diff --git a/cont.c b/cont.c
index 7f971a9e9d5..50403b8258d 100644
--- a/cont.c
+++ b/cont.c
@@ -1930,7 +1930,7 @@ fiber_current(void)
 }
 
 static inline rb_fiber_t*
-return_fiber(void)
+return_fiber(bool terminate)
 {
     rb_fiber_t *fiber = fiber_current();
     rb_fiber_t *prev = fiber->prev;
@@ -1941,7 +1941,7 @@ return_fiber(void)
 
         VM_ASSERT(root_fiber != NULL);
 
-        if (root_fiber == fiber) {
+        if (!terminate && root_fiber == fiber) {
             rb_raise(rb_eFiberError, "can't yield from root fiber");
         }
         return root_fiber;
@@ -2087,7 +2087,7 @@ rb_fiber_terminate(rb_fiber_t *fiber, int need_interrupt)
     fiber->cont.machine.stack = NULL;
     fiber->cont.machine.stack_size = 0;
 
-    next_fiber = return_fiber();
+    next_fiber = return_fiber(true);
     if (need_interrupt) RUBY_VM_SET_INTERRUPT(&next_fiber->cont.saved_ec);
     fiber_switch(next_fiber, 1, &value, 0, RB_NO_KEYWORDS);
 }
@@ -2121,13 +2121,13 @@ rb_fiber_resume(VALUE fiber_value, int argc, const VALUE *argv)
 VALUE
 rb_fiber_yield_kw(int argc, const VALUE *argv, int kw_splat)
 {
-    return fiber_switch(return_fiber(), argc, argv, 0, kw_splat);
+    return fiber_switch(return_fiber(false), argc, argv, 0, kw_splat);
 }
 
 VALUE
 rb_fiber_yield(int argc, const VALUE *argv)
 {
-    return fiber_switch(return_fiber(), argc, argv, 0, RB_NO_KEYWORDS);
+    return fiber_switch(return_fiber(false), argc, argv, 0, RB_NO_KEYWORDS);
 }
 
 void

Updated by naruse (Yui NARUSE) over 2 years ago

  • Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: REQUIRED to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE

ruby_3_1 1c426ddb25e2ccb169720e4f9894605596fe594d merged revision(s) 5c7af72304d0ad33cd3f21b24a4bc44e8acd5b2c,d650b17686d49c2ce8e6a87039861154e93d4621.

Updated by nagachika (Tomoyuki Chikanaga) over 2 years ago

  • Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: REQUIRED, 3.1: DONE to 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE, 3.1: DONE

ruby_3_0 6a8c166498b856ca1dcb53248f0be5fc138f1af3 merged revision(s) 5c7af72304d0ad33cd3f21b24a4bc44e8acd5b2c,d650b17686d49c2ce8e6a87039861154e93d4621.

Actions #6

Updated by usa (Usaku NAKAMURA) over 2 years ago

  • Backport changed from 2.6: REQUIRED, 2.7: REQUIRED, 3.0: DONE, 3.1: DONE to 2.6: WONTFIX, 2.7: DONE, 3.0: DONE, 3.1: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0