ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:88762] [Ruby trunk Bug#15050] GC after forking with fibers crashes
       [not found] <redmine.issue-15050.20180830195441@ruby-lang.org>
@ 2018-08-30 19:54 ` normalperson
  2018-08-30 19:58   ` [ruby-core:88763] " Eric Wong
  2018-08-31  3:01 ` [ruby-core:88767] " ko1
  2018-09-12 22:32 ` [ruby-core:88964] " Greg.mpls
  2 siblings, 1 reply; 10+ messages in thread
From: normalperson @ 2018-08-30 19:54 UTC (permalink / raw
  To: ruby-core

Issue #15050 has been reported by normalperson (Eric Wong).

----------------------------------------
Bug #15050: GC after forking with fibers crashes
https://bugs.ruby-lang.org/issues/15050

* Author: normalperson (Eric Wong)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Not sure when to work on this, so leaving this here for now...

The management of stacks for root fiber and regular
fibers is different and confusing.  Perhaps unifying
thread and fiber stack cache is the best way to go.

Is a separate class of stacks even necessary?
We should aim to minimize use of stack space.

"[BUG] Illegal root fiber parameter"


---Files--------------------------------
0001-test_fiber-show-crash-on-GC-after-forking.patch (1.19 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88763] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
  2018-08-30 19:54 ` [ruby-core:88762] [Ruby trunk Bug#15050] GC after forking with fibers crashes normalperson
@ 2018-08-30 19:58   ` Eric Wong
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Wong @ 2018-08-30 19:58 UTC (permalink / raw
  To: ruby-core

normalperson@yhbt.net wrote:
> https://bugs.ruby-lang.org/issues/15050

This fixes the immediate bug, but I think there's other problems
with stack management

```
diff --git a/cont.c b/cont.c
index 7bc1724176..ab42dfb27a 100644
--- a/cont.c
+++ b/cont.c
@@ -1983,6 +1983,7 @@ rb_fiber_atfork(rb_thread_t *th)
 {
     if (th->root_fiber) {
         if (&th->root_fiber->cont.saved_ec != th->ec) {
+            th->root_fiber->cont.type = FIBER_CONTEXT;
             th->root_fiber = th->ec->fiber_ptr;
             th->root_fiber->cont.type = ROOT_FIBER_CONTEXT;
         }
```

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [ruby-core:88767] [Ruby trunk Bug#15050] GC after forking with fibers crashes
       [not found] <redmine.issue-15050.20180830195441@ruby-lang.org>
  2018-08-30 19:54 ` [ruby-core:88762] [Ruby trunk Bug#15050] GC after forking with fibers crashes normalperson
@ 2018-08-31  3:01 ` ko1
  2018-08-31  3:30   ` [ruby-core:88768] " Eric Wong
  2018-09-12 22:32 ` [ruby-core:88964] " Greg.mpls
  2 siblings, 1 reply; 10+ messages in thread
From: ko1 @ 2018-08-31  3:01 UTC (permalink / raw
  To: ruby-core

Issue #15050 has been updated by ko1 (Koichi Sasada).


Is this because [Bug #15041]?

----------------------------------------
Bug #15050: GC after forking with fibers crashes
https://bugs.ruby-lang.org/issues/15050#change-73815

* Author: normalperson (Eric Wong)
* Status: Open
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Not sure when to work on this, so leaving this here for now...

The management of stacks for root fiber and regular
fibers is different and confusing.  Perhaps unifying
thread and fiber stack cache is the best way to go.

Is a separate class of stacks even necessary?
We should aim to minimize use of stack space.

"[BUG] Illegal root fiber parameter"


---Files--------------------------------
0001-test_fiber-show-crash-on-GC-after-forking.patch (1.19 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88768] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
  2018-08-31  3:01 ` [ruby-core:88767] " ko1
@ 2018-08-31  3:30   ` Eric Wong
       [not found]     ` <85aca733-992b-239e-f953-e228dd33f6d2@atdot.net>
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Wong @ 2018-08-31  3:30 UTC (permalink / raw
  To: ruby-core

ko1@atdot.net wrote:
> Is this because [Bug #15041]?

Yes, fix one bug, hit another :<  Story of my life

(I found these while working on auto-fiber)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88769] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
       [not found]     ` <85aca733-992b-239e-f953-e228dd33f6d2@atdot.net>
@ 2018-08-31  3:50       ` Eric Wong
  2018-08-31  3:52         ` [ruby-core:88770] " Koichi Sasada
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Wong @ 2018-08-31  3:50 UTC (permalink / raw
  To: Koichi Sasada; +Cc: ruby-core

Koichi Sasada <ko1@atdot.net> wrote:
> On 2018/08/31 12:30, Eric Wong wrote:
> > Yes, fix one bug, hit another :<  Story of my life
> 
> [Bug #15041] hits something wrong?
> (sorry I needed to ask earlier)

No, it's not wrong; but it is an incomplete fix.   There
seems to be several problems related to fork + Fiber

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88770] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
  2018-08-31  3:50       ` [ruby-core:88769] " Eric Wong
@ 2018-08-31  3:52         ` Koichi Sasada
  2018-08-31  6:14           ` [ruby-core:88773] " Eric Wong
  0 siblings, 1 reply; 10+ messages in thread
From: Koichi Sasada @ 2018-08-31  3:52 UTC (permalink / raw
  Cc: ruby-core



On 2018/08/31 12:50, Eric Wong wrote:
>> [Bug #15041] hits something wrong?
>> (sorry I needed to ask earlier)
> 
> No, it's not wrong; but it is an incomplete fix.   There
> seems to be several problems related to fork + Fiber

Sorry my question is wrong.

What is the problem [Bug #15041] want to solve?

I remember that there are several implicit assumption on root fiber and 
so on. I think changing this attribute is bad idea now.

-- 
// SASADA Koichi at atdot dot net

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88773] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
  2018-08-31  3:52         ` [ruby-core:88770] " Koichi Sasada
@ 2018-08-31  6:14           ` Eric Wong
  2018-08-31  7:17             ` [ruby-core:88777] " Koichi Sasada
  0 siblings, 1 reply; 10+ messages in thread
From: Eric Wong @ 2018-08-31  6:14 UTC (permalink / raw
  To: ruby-core

Koichi Sasada <ko1@atdot.net> wrote:
> On 2018/08/31 12:50, Eric Wong wrote:
> > > [Bug #15041] hits something wrong?
> > > (sorry I needed to ask earlier)
> > 
> > No, it's not wrong; but it is an incomplete fix.   There
> > seems to be several problems related to fork + Fiber
> 
> Sorry my question is wrong.
> 
> What is the problem [Bug #15041] want to solve?

Switching fiber can crash in child process.  r64589 test change
shows it:

```
-      Fiber.new{ pid = fork {} }.resume
+      Fiber.new do
+        pid = fork do
+          Fiber.new {}.transfer
+        end
+      end.resume
```

> I remember that there are several implicit assumption on root fiber and so
> on. I think changing this attribute is bad idea now.

I think we need to change to avoid crashes.  We change vm->main_thread
at fork, too.  Maybe I'can investigate late next week.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88777] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
  2018-08-31  6:14           ` [ruby-core:88773] " Eric Wong
@ 2018-08-31  7:17             ` Koichi Sasada
  2018-09-09 10:08               ` [ruby-core:88919] " Eric Wong
  0 siblings, 1 reply; 10+ messages in thread
From: Koichi Sasada @ 2018-08-31  7:17 UTC (permalink / raw
  To: Ruby developers

On 2018/08/31 15:14, Eric Wong wrote:
>> What is the problem [Bug #15041] want to solve?
> 
> Switching fiber can crash in child process.  r64589 test change
> shows it:
> 
> ```
> -      Fiber.new{ pid = fork {} }.resume
> +      Fiber.new do
> +        pid = fork do
> +          Fiber.new {}.transfer
> +        end
> +      end.resume
> ```
> 
>> I remember that there are several implicit assumption on root fiber and so
>> on. I think changing this attribute is bad idea now.
> 
> I think we need to change to avoid crashes.  We change vm->main_thread
> at fork, too.  Maybe I'can investigate late next week.

Ok. We need to avoid this kind of crash.

-- 
// SASADA Koichi at atdot dot net

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88919] Re: [Ruby trunk Bug#15050] GC after forking with fibers crashes
  2018-08-31  7:17             ` [ruby-core:88777] " Koichi Sasada
@ 2018-09-09 10:08               ` Eric Wong
  0 siblings, 0 replies; 10+ messages in thread
From: Eric Wong @ 2018-09-09 10:08 UTC (permalink / raw
  To: ruby-core; +Cc: MSP-Greg

Koichi Sasada <ko1@atdot.net> wrote:
> Ok. We need to avoid this kind of crash.
> 
> https://bugs.ruby-lang.org/issues/15050

OK, I think I fixed the issue (also including [Feature #15095])

Greg, there's a small win32-specific change in this series which
seems low risk, but I figured I'd Cc you anyways for testing.
Thanks.

Pull request:

  The following changes since commit 64b326c2204e562aa3d6025ca097a82bcf4de303:

    spec/ruby/library/socket/addrinfo: require for SocketSpecs (2018-09-09 08:50:53 +0000)

  are available in the Git repository at:

    https://80x24.org/ruby.git fiber-fork

  for you to fetch changes up to ce0a6005fbf78203b3bcaa4b90bf94b8b5c44782:

    fiber: fix crash on GC after forking (2018-09-09 09:49:55 +0000)

Or broken out patches:

  * [PATCH 1/4] share VM stack between threads and fibers if identical
    https://80x24.org/spew/20180909095347.30757-2-e@80x24.org/raw

  * [PATCH 2/4] cont.c (ec_set_vm_stack): avoid needless casting
    https://80x24.org/spew/20180909095347.30757-3-e@80x24.org/raw

  * [PATCH 3/4] cont.c (fiber_memsize): do not rely on ROOT_FIBER_CONTEXT
    https://80x24.org/spew/20180909095347.30757-4-e@80x24.org/raw

  * [PATCH 4/4] fiber: fix crash on GC after forking
    https://80x24.org/spew/20180909095347.30757-5-e@80x24.org/raw

Or full diff against current trunk (r64663):

  https://80x24.org/spew/20180909100319.ild2rlncrmmm2lwp@whir/raw

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [ruby-core:88964] [Ruby trunk Bug#15050] GC after forking with fibers crashes
       [not found] <redmine.issue-15050.20180830195441@ruby-lang.org>
  2018-08-30 19:54 ` [ruby-core:88762] [Ruby trunk Bug#15050] GC after forking with fibers crashes normalperson
  2018-08-31  3:01 ` [ruby-core:88767] " ko1
@ 2018-09-12 22:32 ` Greg.mpls
  2 siblings, 0 replies; 10+ messages in thread
From: Greg.mpls @ 2018-09-12 22:32 UTC (permalink / raw
  To: ruby-core

Issue #15050 has been updated by MSP-Greg (Greg L).


@normalperson

Eric,

Sorry been busy with 'this is a bigger mess than I thought' kinds of things.

I just ran ruby-loco on r64706 'fiber: fix crash on GC after forking', and the build passed.

Thanks, Greg

----------------------------------------
Bug #15050: GC after forking with fibers crashes
https://bugs.ruby-lang.org/issues/15050#change-73996

* Author: normalperson (Eric Wong)
* Status: Closed
* Priority: Normal
* Assignee: ko1 (Koichi Sasada)
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Not sure when to work on this, so leaving this here for now...

The management of stacks for root fiber and regular
fibers is different and confusing.  Perhaps unifying
thread and fiber stack cache is the best way to go.

Is a separate class of stacks even necessary?
We should aim to minimize use of stack space.

"[BUG] Illegal root fiber parameter"


---Files--------------------------------
0001-test_fiber-show-crash-on-GC-after-forking.patch (1.19 KB)


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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-09-12 22:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-15050.20180830195441@ruby-lang.org>
2018-08-30 19:54 ` [ruby-core:88762] [Ruby trunk Bug#15050] GC after forking with fibers crashes normalperson
2018-08-30 19:58   ` [ruby-core:88763] " Eric Wong
2018-08-31  3:01 ` [ruby-core:88767] " ko1
2018-08-31  3:30   ` [ruby-core:88768] " Eric Wong
     [not found]     ` <85aca733-992b-239e-f953-e228dd33f6d2@atdot.net>
2018-08-31  3:50       ` [ruby-core:88769] " Eric Wong
2018-08-31  3:52         ` [ruby-core:88770] " Koichi Sasada
2018-08-31  6:14           ` [ruby-core:88773] " Eric Wong
2018-08-31  7:17             ` [ruby-core:88777] " Koichi Sasada
2018-09-09 10:08               ` [ruby-core:88919] " Eric Wong
2018-09-12 22:32 ` [ruby-core:88964] " Greg.mpls

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).