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

fiber stack issues with crystal 13 #89

Open
phil294 opened this issue Aug 4, 2024 · 3 comments
Open

fiber stack issues with crystal 13 #89

phil294 opened this issue Aug 4, 2024 · 3 comments

Comments

@phil294
Copy link
Owner

phil294 commented Aug 4, 2024

$ bin/ahk_x11.dev <<<'a = 1
$ b := a
$ echo %b%'
[debug] 0: a = 1
[debug] 1: b := a
[debug] 2: echo %b%
[debug] 3: 
[debug] x11: root_win = 1500
[debug] x11: _NET_ACTIVE_WINDOW = 346
[debug] x11: active window detection: 77594635
Failed to raise an exception: END_OF_STACK
[0x66de46] *Exception::CallStack::print_backtrace:Nil +118 in bin/ahk_x11.dev
[0x61a334] __crystal_raise +52 in bin/ahk_x11.dev
[0x62c461] ?? +6472801 in bin/ahk_x11.dev
[0x62c3e7] ?? +6472679 in bin/ahk_x11.dev
[0x76f05f] *Thread#main_fiber:Fiber +63 in bin/ahk_x11.dev
[0x76db52] *Crystal::Scheduler#initialize<Thread>:Deque(Fiber) +34 in bin/ahk_x11.dev
[0x76db21] *Crystal::Scheduler::new<Thread>:Crystal::Scheduler +129 in bin/ahk_x11.dev
[0x76eff5] *Thread#scheduler:Crystal::Scheduler +53 in bin/ahk_x11.dev
[0x76dc0e] *Crystal::Scheduler::event_loop:Crystal::EventLoop+ +14 in bin/ahk_x11.dev
[0x7704c6] *Crystal::EventLoop::current:Crystal::EventLoop+ +6 in bin/ahk_x11.dev
[0x7c3fa6] *File +6 in bin/ahk_x11.dev
[0x7c490a] *File +10 in bin/ahk_x11.dev
[0x7c48fc] *File +28 in bin/ahk_x11.dev
[0x7c3d77] *File +103 in bin/ahk_x11.dev
[0xa4c68a] *Compiler#finalize:Nil +10 in bin/ahk_x11.dev
[0x6454e6] ~proc11Proc(Pointer(Void), Pointer(Void), Nil) +6 in bin/ahk_x11.dev
[0x7fd38c9d70df] GC_invoke_finalizers +79 in /usr/lib/libgc.so.1
[0x7fd38c9d730e] ?? +140546573955854 in /usr/lib/libgc.so.1
[0x7fd38c9e2095] GC_generic_malloc +37 in /usr/lib/libgc.so.1
[0x7fd38c9e23d7] GC_malloc_kind_global +295 in /usr/lib/libgc.so.1
[0x6f8ece] *GC::malloc<UInt64>:Pointer(Void) +62 in bin/ahk_x11.dev
[0x6198de] __crystal_malloc64 +14 in bin/ahk_x11.dev
[0x76ba6c] *Fiber::new<Pointer(Void), Thread>:Fiber +28 in bin/ahk_x11.dev
[0x76f35f] *Thread#start:(Exception+ | Nil) +63 in bin/ahk_x11.dev
[0x63de86] ~procProc(Pointer(Void), Pointer(Void)) +6 in bin/ahk_x11.dev
[0x7fd38c9f098e] ?? +140546574059918 in /usr/lib/libgc.so.1
[0x7fd38c9ee349] GC_call_with_stack_base +41 in /usr/lib/libgc.so.1
[0x7fd38b479ded] ?? +140546551553517 in /usr/lib/libc.so.6
[0x7fd38b4fd0dc] ?? +140546552090844 in /usr/lib/libc.so.6
[0x0] ???

Tried to raise:: Thread#main_fiber cannot be nil (NilAssertionError)
Unable to load dwarf information: Thread#main_fiber cannot be nil (NilAssertionError)
  from bin/ahk_x11.dev in 'Exception::CallStack::unwind:Array(Pointer(Void))'
  from bin/ahk_x11.dev in 'Exception::CallStack#initialize:Array(Pointer(Void))'
  from bin/ahk_x11.dev in 'Exception::CallStack::new:Exception::CallStack'
  from bin/ahk_x11.dev in 'raise<NilAssertionError>:NoReturn'
  from bin/ahk_x11.dev in 'Thread#main_fiber:Fiber'
  from bin/ahk_x11.dev in 'Crystal::Scheduler#initialize<Thread>:Deque(Fiber)'
  from bin/ahk_x11.dev in 'Crystal::Scheduler::new<Thread>:Crystal::Scheduler'
  from bin/ahk_x11.dev in 'Thread#scheduler:Crystal::Scheduler'
  from bin/ahk_x11.dev in 'Crystal::Scheduler::event_loop:Crystal::EventLoop+'
  from bin/ahk_x11.dev in 'Crystal::EventLoop::current:Crystal::EventLoop+'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'Exception::CallStack::read_dwarf_sections<String, UInt64>:(Array(Tuple(UInt64, UInt64, String)) | Nil)'
  from bin/ahk_x11.dev in 'Exception::CallStack::load_debug_info_impl:Nil'
  from bin/ahk_x11.dev in 'Exception::CallStack::load_debug_info:Nil'
  from bin/ahk_x11.dev in 'Exception::CallStack::decode_line_number<UInt64>:Tuple(String, Int32, Int32)'
  from bin/ahk_x11.dev in 'Exception::CallStack#decode_backtrace:Array(String)'
  from bin/ahk_x11.dev in 'Exception::CallStack#printable_backtrace:Array(String)'
  from bin/ahk_x11.dev in 'Exception+'
  from bin/ahk_x11.dev in 'Crystal::System::print_exception<String, Exception+>:Nil'
  from bin/ahk_x11.dev in '__crystal_raise'
  from bin/ahk_x11.dev in '??'
  from bin/ahk_x11.dev in '??'
  from bin/ahk_x11.dev in 'Thread#main_fiber:Fiber'
  from bin/ahk_x11.dev in 'Crystal::Scheduler#initialize<Thread>:Deque(Fiber)'
  from bin/ahk_x11.dev in 'Crystal::Scheduler::new<Thread>:Crystal::Scheduler'
  from bin/ahk_x11.dev in 'Thread#scheduler:Crystal::Scheduler'
  from bin/ahk_x11.dev in 'Crystal::Scheduler::event_loop:Crystal::EventLoop+'
  from bin/ahk_x11.dev in 'Crystal::EventLoop::current:Crystal::EventLoop+'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'Compiler#finalize:Nil'
  from bin/ahk_x11.dev in '~proc11Proc(Pointer(Void), Pointer(Void), Nil)'
  from /usr/lib/libgc.so.1 in 'GC_invoke_finalizers'
  from /usr/lib/libgc.so.1 in '??'
  from /usr/lib/libgc.so.1 in 'GC_generic_malloc'
  from /usr/lib/libgc.so.1 in 'GC_malloc_kind_global'
  from bin/ahk_x11.dev in 'GC::malloc<UInt64>:Pointer(Void)'
  from bin/ahk_x11.dev in '__crystal_malloc64'
  from bin/ahk_x11.dev in 'Fiber::new<Pointer(Void), Thread>:Fiber'
  from bin/ahk_x11.dev in 'Thread#start:(Exception+ | Nil)'
  from bin/ahk_x11.dev in '~procProc(Pointer(Void), Pointer(Void))'
  from /usr/lib/libgc.so.1 in '??'
  from /usr/lib/libgc.so.1 in 'GC_call_with_stack_base'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '??'
  from ???
  from bin/ahk_x11.dev in 'Exception::CallStack::unwind:Array(Pointer(Void))'
  from bin/ahk_x11.dev in 'Exception::CallStack#initialize:Array(Pointer(Void))'
  from bin/ahk_x11.dev in 'Exception::CallStack::new:Exception::CallStack'
  from bin/ahk_x11.dev in 'raise<NilAssertionError>:NoReturn'
  from bin/ahk_x11.dev in 'Thread#main_fiber:Fiber'
  from bin/ahk_x11.dev in 'Crystal::Scheduler#initialize<Thread>:Deque(Fiber)'
  from bin/ahk_x11.dev in 'Crystal::Scheduler::new<Thread>:Crystal::Scheduler'
  from bin/ahk_x11.dev in 'Thread#scheduler:Crystal::Scheduler'
  from bin/ahk_x11.dev in 'Crystal::Scheduler::event_loop:Crystal::EventLoop+'
  from bin/ahk_x11.dev in 'Crystal::EventLoop::current:Crystal::EventLoop+'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'File'
  from bin/ahk_x11.dev in 'Compiler#finalize:Nil'
  from bin/ahk_x11.dev in '~proc11Proc(Pointer(Void), Pointer(Void), Nil)'
  from /usr/lib/libgc.so.1 in 'GC_invoke_finalizers'
  from /usr/lib/libgc.so.1 in '??'
  from /usr/lib/libgc.so.1 in 'GC_generic_malloc'
  from /usr/lib/libgc.so.1 in 'GC_malloc_kind_global'
  from bin/ahk_x11.dev in 'GC::malloc<UInt64>:Pointer(Void)'
  from bin/ahk_x11.dev in '__crystal_malloc64'
  from bin/ahk_x11.dev in 'Fiber::new<Pointer(Void), Thread>:Fiber'
  from bin/ahk_x11.dev in 'Thread#start:(Exception+ | Nil)'
  from bin/ahk_x11.dev in '~procProc(Pointer(Void), Pointer(Void))'
  from /usr/lib/libgc.so.1 in '??'
  from /usr/lib/libgc.so.1 in 'GC_call_with_stack_base'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '??'
  from ???

I have no idea what this is and how to fix it, so I'll downgrade to Crystal 1.11 for the time being. Likely related to the fiber run override in hacks.cr

@donovanglover
Copy link

Is this fixable with 1.15? Seems like a lot has changed since crystal-lang/crystal@c3eb0eb

@donovanglover
Copy link

Builds for me when removing the custom Fiber code:

AHK_X11/src/hacks.cr

Lines 50 to 88 in 66eb520

# https://github.com/crystal-lang/crystal/issues/13297
class Fiber
# Code copied over and extended from stdlib
def run
GC.unlock_read
@proc.call
rescue ex
if handler = Hacks.fiber_on_unhandled_exception
handler.call ex
else
if name = @name
STDERR.print "Unhandled exception in spawn (name: #{name}): "
else
STDERR.print "Unhandled exception in spawn: "
end
ex.inspect_with_backtrace(STDERR)
STDERR.flush
end
ensure
{% if flag?(:preview_mt) %}
Crystal::Scheduler.enqueue_free_stack @stack
{% elsif flag?(:interpreted) %}
# For interpreted mode we don't need a new stack, the stack is held by the interpreter
{% else %}
Fiber.stack_pool.release(@stack)
{% end %}
# Remove the current fiber from the linked list
Fiber.fibers.delete(self)
# Delete the resume event if it was used by `yield` or `sleep`
@resume_event.try &.free
@timeout_event.try &.free
@timeout_select_action = nil
@alive = false
Crystal::Scheduler.reschedule
end
end

Seems like some wait_readable changes broke ./src/run/display/x11.cr in 1.15 which is another issue. Looks like they were internal APIs not meant to be used by users.

@phil294
Copy link
Owner Author

phil294 commented Feb 20, 2025

Thanks for looking this up. this is unfortunate, but I can't be bothered to chase after a replacement for something that was needlessly removed. If the Crystal team decides to break stuff, I'd rather just fix version 1.11 in place, never upgrade again and be done with it.

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

No branches or pull requests

2 participants