Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ec assertion with using pthread #10468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peterzhu2118
Copy link
Member

When RUBY_DEBUG is enabled, the following script causes an assertion failure:

Fiber.new(&Object.method(:class_eval)).resume("foo")

The assertion failure is:

Assertion Failed: ractor_core.h:328:rb_ractor_set_current_ec_:ec == ((void*)0) || cr->threads.running_ec != ec

-- C level backtrace information -------------------------------------------
miniruby(rb_vm_bugreport+0xb60) [0x100290f20] vm_dump.c:1151
miniruby(rb_vm_bugreport) (null):0
miniruby(rb_assert_failure_detail+0xa4) [0x1003b533c] error.c:1168
miniruby(rb_assert_failure_detail+0x0) [0x1003b5298] error.c:1148
miniruby(rb_assert_failure) (null):0
miniruby(Init_native_thread.cold.1+0x0) [0x1003d3c24] ractor_core.h:328
miniruby(rb_ractor_set_current_ec_) (null):0
miniruby(ruby_thread_set_native.cold.1) thread_pthread.c:1624
miniruby(Init_native_thread+0x0) [0x100222380] ractor_core.h:328
miniruby(ruby_thread_set_native) (null):0
miniruby(fiber_entry+0x1c) [0x10008a1c4] cont.c:845
miniruby(coroutine_trampoline+0xa8) [0x1003a1d78] coroutine/pthread/Context.c:148
/usr/lib/system/libsystem_pthread.dylib(_pthread_start+0x88) [0x1911fef94]

When RUBY_DEBUG is enabled, the following script causes an assertion
failure:

    Fiber.new(&Object.method(:class_eval)).resume("foo")

The assertion failure is:

    Assertion Failed: ractor_core.h:328:rb_ractor_set_current_ec_:ec == ((void*)0) || cr->threads.running_ec != ec

    -- C level backtrace information -------------------------------------------
    miniruby(rb_vm_bugreport+0xb60) [0x100290f20] vm_dump.c:1151
    miniruby(rb_vm_bugreport) (null):0
    miniruby(rb_assert_failure_detail+0xa4) [0x1003b533c] error.c:1168
    miniruby(rb_assert_failure_detail+0x0) [0x1003b5298] error.c:1148
    miniruby(rb_assert_failure) (null):0
    miniruby(Init_native_thread.cold.1+0x0) [0x1003d3c24] ractor_core.h:328
    miniruby(rb_ractor_set_current_ec_) (null):0
    miniruby(ruby_thread_set_native.cold.1) thread_pthread.c:1624
    miniruby(Init_native_thread+0x0) [0x100222380] ractor_core.h:328
    miniruby(ruby_thread_set_native) (null):0
    miniruby(fiber_entry+0x1c) [0x10008a1c4] cont.c:845
    miniruby(coroutine_trampoline+0xa8) [0x1003a1d78] coroutine/pthread/Context.c:148
    /usr/lib/system/libsystem_pthread.dylib(_pthread_start+0x88) [0x1911fef94]
@nobu nobu requested a review from ko1 April 8, 2024 02:14
@ko1
Copy link
Contributor

ko1 commented Apr 8, 2024

I couldn't reproduce this issue because of the following error.

$ ./miniruby -v -e 'Fiber.new(&Object.method(:class_eval)).resume("foo")'
ruby 3.4.0dev (2024-04-08T02:13:29Z master 4dd9e5cf74) [x86_64-linux]
-e:in 'Module#class_eval': Can't eval on top of Fiber or Thread (RuntimeError)

Do I missing something?

@ko1
Copy link
Contributor

ko1 commented Apr 8, 2024

This assertion represents that nobody set same ec to itself.
If this assertion is wrong, we need to understand why.

@peterzhu2118
Copy link
Member Author

@ko1 I configured with CPPFLAGS=-DRUBY_DEBUG ../configure --with-coroutine=pthread and I ran ./miniruby -v -e 'Fiber.new(&Object.method(:class_eval)).resume("foo")'

And I got:

ruby 3.4.0dev (2024-04-09T13:50:09Z master 0bc71828b5) [arm64-darwin23]
last_commit=[pty] Split `chfunc` into functions in steps
Assertion Failed: ractor_core.h:328:rb_ractor_set_current_ec_:ec == ((void*)0) || cr->threads.running_ec != ec

@peterzhu2118
Copy link
Member Author

It's happening because th->ractor->threads.running_ec == th->ec is true at boot, so calling ruby_thread_set_native again will cause it to have an assertion failure.

I opened #10491 as an alternative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants