Bug 705425

Summary: ruby-bindings: YaST crash during the call of ruby method
Product: [openSUSE] openSUSE 11.4 Reporter: Jiří Suchomel <jsuchome>
Component: YaST2Assignee: Duncan Mac-Vicar <dmacvicar>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Critical    
Priority: P3 - Medium CC: jreidinger, kkaempf, mvidner
Version: Final   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: Development Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Bug Depends on:    
Bug Blocks: 708059    
Attachments: modified Kerberos.ycp
ruby module
backtrace

Description Jiří Suchomel 2011-07-13 12:45:56 UTC
KerberosClient.rb is located under /usr/share/YaST2/modules

modified Kerberos.ycp is importing KerberosClient.rb and tries to call read function from that module

It crashes with these last lines in y2log:

2011-07-13 14:42:51 <1> dhcp74.suse.cz(18030) [Y2Ruby] ruby/YRuby.cc(callInner):164 Adding argument 0 of type MAP
2011-07-13 14:42:51 <1> dhcp74.suse.cz(18030) [Y2Ruby] ruby/YRuby.cc(callInner):168 Wll call function 'read' in module 'KerberosClient' with '1' arguments
Comment 1 Jiří Suchomel 2011-07-13 12:46:42 UTC
Created attachment 439666 [details]
modified Kerberos.ycp
Comment 2 Jiří Suchomel 2011-07-13 12:47:22 UTC
Created attachment 439668 [details]
ruby module
Comment 3 Jiří Suchomel 2011-07-13 12:52:56 UTC
Created attachment 439669 [details]
backtrace
Comment 4 Josef Reidinger 2011-07-14 12:24:15 UTC
We investigate that stack is broken. We expect that ruby bindings somehow break it as it works without ruby bindings.
Comment 5 Klaus Kämpf 2011-07-14 15:10:16 UTC
Please provide a complete description on how to reproduce the bug
Comment 6 Jiří Suchomel 2011-07-14 15:30:11 UTC
1. Download yast-- project from https://github.com/yast/yast--

2. Follow the README to install the project.

3. YaST needs library files under YaST directory and with YaST-like name: link kerberos_client.rb (https://github.com/yast/yast--/blob/master/kerberos-client/kerberos_client.rb) to /usr/share/YaST2/modules/KerberosClient.rb

(btw, there are bugs 705422, 705417 for this)

4. Run this ycp code:

{
    import "KerberosClient";
    y2internal ("read: %1", KerberosClient::read ($[]));
}
Comment 7 Josef Reidinger 2011-07-14 15:55:12 UTC
I simplify code much more. I extract call from ruby bindings how it does it and reproduce crash. It is at https://github.com/yast/yast-- located in directory testC
Comment 8 Josef Reidinger 2011-07-14 16:27:58 UTC
well, C code actually works, my fault.
Comment 9 Klaus Kämpf 2011-07-18 08:44:21 UTC
(In reply to comment #6)
> 1. Download yast-- project from https://github.com/yast/yast--
> 
> 2. Follow the README to install the project.

Please fix this. Testing YaST-- and reproducing bugs must not require root privileges.

> 
> 3. YaST needs library files under YaST directory and with YaST-like name: link
> kerberos_client.rb
> (https://github.com/yast/yast--/blob/master/kerberos-client/kerberos_client.rb)
> to /usr/share/YaST2/modules/KerberosClient.rb

See above

> 
> (btw, there are bugs 705422, 705417 for this)
> 
> 4. Run this ycp code:

How does one run this code ?

> 
> {
>     import "KerberosClient";
>     y2internal ("read: %1", KerberosClient::read ($[]));
> }
Comment 10 Jiří Suchomel 2011-07-18 08:48:35 UTC
(In reply to comment #9)
> (In reply to comment #6)
> > 1. Download yast-- project from https://github.com/yast/yast--
> > 
> > 2. Follow the README to install the project.
> 
> Please fix this. Testing YaST-- and reproducing bugs must not require root
> privileges.

You need root privileges for 'sudo rake install', which is usual for any project.
 
> > 3. YaST needs library files under YaST directory and with YaST-like name: link
> > kerberos_client.rb
> > (https://github.com/yast/yast--/blob/master/kerberos-client/kerberos_client.rb)
> > to /usr/share/YaST2/modules/KerberosClient.rb
> 
> See above

This is workaround for another ruby-bindings bugs, as already mentioned:

> > (btw, there are bugs 705422, 705417 for this)


> > 4. Run this ycp code:
> 
> How does one run this code ?

/sbin/yast2 ./this_example.ycp
Comment 11 Klaus Kämpf 2011-07-18 08:58:24 UTC
(In reply to comment #10)
> (In reply to comment #9)
> > (In reply to comment #6)
> > > 1. Download yast-- project from https://github.com/yast/yast--
> > > 
> > > 2. Follow the README to install the project.
> > 
> > Please fix this. Testing YaST-- and reproducing bugs must not require root
> > privileges.
> 
> You need root privileges for 'sudo rake install', which is usual for any
> project.

But completely wrong for development and testing IMHO.
Comment 12 Jiří Suchomel 2011-07-18 09:21:33 UTC
(In reply to comment #11)

> > > Please fix this. Testing YaST-- and reproducing bugs must not require root
> > > privileges.
> > 
> > You need root privileges for 'sudo rake install', which is usual for any
> > project.
> 
> But completely wrong for development and testing IMHO.

AFAIK it's for the D-BUS stuff which needs to be in correct directory.

Anyway, it is sure that the project needs improvements on all parts, including configuration. That may be point of bugs against YaST++ project, but not of this one, which shows problems in ruby-bindings.
Comment 13 Duncan Mac-Vicar 2011-07-18 10:05:39 UTC
I discussed this bug with Jiri during the workshop. The reason it happens is because the bindings use Method#arity when it should probably use Method#parameters (as detailed in the ruby-doc).

Method#arity returns negative numbers when there are optional parameters and this causes the crash. So YCP should always call ruby passing _all_ parameters of a ruby method with optional arguments.

Sadly, the advertised Merthod#parameters (http://www.ruby-doc.org/core/classes/Method.html#M001075) does not seem to be available in the interpreter.
Comment 14 Jiří Suchomel 2011-07-18 10:11:25 UTC
(In reply to comment #13)
> I discussed this bug with Jiri during the workshop. The reason it happens is
> because the bindings use Method#arity when it should probably use
> Method#parameters (as detailed in the ruby-doc).

No, you are referring to a different one: bug 705420
Comment 15 Klaus Kämpf 2011-07-25 08:33:56 UTC
Hmm, I don't get a crash but

2011-07-25 10:30:14 <3> heron(19808) [Parser] yast--/bnc705425.ycp:3 Excessive parameter in call to KerberosClient::read(...)
2011-07-25 10:30:14 <3> heron(19808) [Parser] yast--/bnc705425.ycp:3 Bad parameter '<map> $[]'
2011-07-25 10:30:14 <1> heron(19808) [wfm] Y2CCWFM.cc(createInLevel):148 Parsing finished
2011-07-25 10:30:14 <3> heron(19808) [liby2] genericfrontend.cc(print_error):920 Error while creating client module ./bnc705425.ycp
Comment 16 Klaus Kämpf 2011-07-25 08:50:36 UTC
The problem is arity being -1 for a 'varargs'-like parameter list. This is not handled properly by yast2-ruby-bindings.
Comment 17 Jiří Suchomel 2011-07-25 09:07:04 UTC
(In reply to comment #16)
> The problem is arity being -1 for a 'varargs'-like parameter list. This is not
> handled properly by yast2-ruby-bindings.

Which is bug 705420.

As a workaround, it should work to call  KerberosClient::read () from example ycp code (without argument).

Or remove default argument value from read function of 
https://github.com/yast/yast--/blob/master/kerberos-client/kerberos_client.rb
Comment 18 Klaus Kämpf 2011-07-25 09:08:09 UTC
A good fix would require Ruby 1.9 (which has Method#parameters). We could make this a pre-requisite for further YaST++ development ...
Comment 19 Jiří Suchomel 2011-07-25 09:11:37 UTC
We could live (and develop) with arity bug not being fixed. The real pain is this crash bug.

(In reply to comment #17)

> Or remove default argument value from read function of 
> https://github.com/yast/yast--/blob/master/kerberos-client/kerberos_client.rb

I just did it in git.
Comment 20 Klaus Kämpf 2011-07-25 09:24:06 UTC
(In reply to comment #17)
> (In reply to comment #16)
> > The problem is arity being -1 for a 'varargs'-like parameter list. This is not
> > handled properly by yast2-ruby-bindings.
> 
> Which is bug 705420.
> 
> As a workaround, it should work to call  KerberosClient::read () from example
> ycp code (without argument).
> 
> Or remove default argument value from read function of 
> https://github.com/yast/yast--/blob/master/kerberos-client/kerberos_client.rb

Right, now I get a segfault
Comment 21 Klaus Kämpf 2011-07-25 09:37:43 UTC
gdb shows:


#0  0x00007f31dff9896f in jump_tag_but_local_jump (state=6, val=<value optimized out>) at eval.c:1853
1853	    JUMP_TAG(state);

state == 6 means 'TAG_RAISE' ?!

Code is:


#define JUMP_TAG(st) do {               \
    ruby_frame = prot_tag->frame;       \
    ruby_iter = prot_tag->iter;         \
    ruby_longjmp(prot_tag->buf,(st));   \
} while (0)

and

(gdb) print prot_tag
$2 = (struct tag *) 0x0
Comment 22 Martin Vidner 2011-07-25 11:30:21 UTC
During the workshop Pepa and I found that it is trying to raise a SystemStackError. Looking into that, we found that there seems to be no particularly deep recursion. Maybe we are omitting some initialization step in the bindings.
Comment 23 Klaus Kämpf 2011-07-25 11:40:49 UTC
(In reply to comment #22)
> During the workshop Pepa and I found that it is trying to raise a
> SystemStackError.
Ah, this would explain the TAG_RAISE

> Looking into that, we found that there seems to be no
> particularly deep recursion. Maybe we are omitting some initialization step in
> the bindings.

I was comparing the initialization with the one from cmpi-bindings-ruby and couldn't find a difference.
Comment 24 Klaus Kämpf 2011-07-25 13:12:37 UTC
The segfault is fixed now. Will checkin in a moment.

This brought me on the right track:
http://objectmix.com/ruby/749825-re-rb_require-causes-segfault.html

(Bottom line: You _have_ to wrap your rb_funcall in rb_protect if the funcall might raise an exception)
Comment 25 Klaus Kämpf 2011-07-25 13:21:40 UTC
Now I get:


2011-07-25 15:20:31 <3> heron(10453) [Y2Ruby] ruby/YRuby.cc(callInner):219 KerberosClient.read failed
stack level too deep
        /usr/lib64/ruby/site_ruby/1.8/dbus/bus.rb:211:in `initialize'
        /usr/lib64/ruby/site_ruby/1.8/dbus/bus.rb:686:in `initialize'
        /usr/lib64/ruby/1.8/singleton.rb:94:in `new'
        /usr/lib64/ruby/1.8/singleton.rb:94:in `instance'
        /usr/lib64/ruby/vendor_ruby/1.8/dbus_clients/file_client.rb:30:in `dbus_object'
        /usr/lib64/ruby/vendor_ruby/1.8/dbus_clients/file_client.rb:14:in `read'
        /abuild/projects/yast/yast--/kerberos-client/kerberos_client.rb:10:in `read'


but thats a different problem.
Comment 26 Jiří Suchomel 2011-07-25 13:34:10 UTC
Cool! Do you we already have a bug report for the new bug?
Comment 27 Klaus Kämpf 2011-07-25 13:35:22 UTC
And the 'different problem' might be this one:

http://stackoverflow.com/questions/4082989/calling-ruby-function-from-c-in-a-loop-results-in-stack-level-too-deep
Comment 28 Klaus Kämpf 2011-07-25 13:39:23 UTC
(In reply to comment #26)
> Cool! Do you we already have a bug report for the new bug?

bnc#708059
Comment 29 Bernhard Wiedemann 2011-07-26 15:00:36 UTC
This is an autogenerated message for OBS integration:
This bug (705425) was mentioned in
https://build.opensuse.org/request/show/77099 Factory / yast2-ruby-bindings