Because involves code is quite complicated, so get a minimum reproduce code is not easy.
When i run my code, i get error like this:
╰─ $ cr run -d src/procodile.cr – status
Invalid memory access (signal 11) at address 0x0
[0x555a2a973b86] *Exception::CallStack::print_backtrace:Nil +118 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x555a2a958b2e] ~procProc(Int32, Pointer(LibC::SiginfoT), Pointer(Void), Nil) +366 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x7f0bd4462a00] ?? +139688782735872 in /usr/lib/libc.so.6
[0x555a2a95eac8] ~procProc((Procodile::ControlClientReplyForStatusCommand | Nil)) +40 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x555a2aa781f8] *Procodile::CLI#dispatch:Nil +248 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x555a2a946bd4] __crystal_main +4356 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x555a2ab924bd] *Crystal::main_user_code<Int32, Pointer(Pointer(UInt8))>:Nil +45 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x555a2ab923fe] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +94 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x555a2a954a7d] main +45 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x7f0bd444d290] ?? +139688782647952 in /usr/lib/libc.so.6
[0x7f0bd444d34a] __libc_start_main +138 in /usr/lib/libc.so.6
[0x555a2a9459f5] _start +37 in /home/zw963/.cache/crystal/crystal-run-procodile.tmp
[0x0] ???
I know why this issue happen, fix is quite easy, when i add a nil
in following code, or add a : Nil
return type declaration enforce the status
method always return nil, code works.
Because status method was convertd to a Proc and by used in src/procodile/cli.cr#L60 like this:
callable = ->status
callable.as(Proc(Nil)).call # Cast to a Proc(Nil) here.
But, the issue is, it should raise a cast error like following instead of Invalid memory access.
Unhandled exception: cast from Proc((ControlClientReplyForStatusCommand | Nil)) to Proc(Nil) failed, at /home/zw963/Crystal/git/procodile.cr/1.cr:85:1:85 (TypeCastError)
So, assume i am not use any unsafe or low level primitives, when invalid memory access error often happen? What tools should i use to debug that?
reproduce:
- clone GitHub - zw963/procodile_cr: 🐊 Run processes in the background (and foreground) on Mac & Linux from a Procfile (for production and/or development environments)
- create a Procfile like this:
test1: sleep 1000000
test2: sleep 1000000
- start daemon in one terminal
crystal run -d src/procodile.cr – start --clean --foreground
- open a new terminal, check the daemon status
crystal run -d src/procodile.cr -- status
- comment the above nil in
src/procodile/commands/status_command.cr:31
, repeat 4 again.
Thanks