embedding ruby - segfault after initialization when runningrb_gc_start??

Discussion in 'Ruby' started by Marc Weber, Dec 6, 2010.

  1. Marc Weber

    Marc Weber Guest

    Hi,

    I'm trying to embed Ruby into the Ur web programming language.

    Everything seems to work fine when using rb_gc_disable().
    When not disabling gc it segfaults when requiring 'net/http'.

    Then I tried running gc manually and found out that the crash even
    happens after initialization.

    However it only happens when urweb compiles everything. Compiling a
    embed ruby into C test case everything is fine.

    What could be causing this?

    valgrind log, initialization code:
    http://mawercer.de/~marc/crash.txt

    Any ideas? Could symbol collisions cause this?
    The libruby.so file is used. Ruby version is 1.9.2-p0

    The strange thing is that the segfault only happens when being called
    within urweb.

    Marc Weber
     
    Marc Weber, Dec 6, 2010
    #1
    1. Advertising

  2. Marc Weber

    Ammar Ali Guest

    On Mon, Dec 6, 2010 at 6:47 PM, Marc Weber <> wrote:
    > Hi,
    >
    > I'm trying to embed Ruby into the Ur web programming language.
    >
    > Everything seems to work fine when using rb_gc_disable().
    > When not disabling gc it segfaults when requiring 'net/http'.
    >
    > Then I tried running gc manually and found out that the crash even
    > happens after initialization.
    >
    > However it only happens when urweb compiles everything. Compiling a
    > embed ruby into C test case everything is fine.
    >
    > What could be causing this?
    >
    > valgrind log, initialization code:
    > http://mawercer.de/~marc/crash.txt
    >
    > Any ideas? Could symbol collisions cause this?
    > The libruby.so file is used. Ruby version is 1.9.2-p0
    >
    > The strange thing is that the segfault only happens when being called
    > within urweb.


    Is this a multithreaded environment? If so, it sounds vaguely like the
    problem discussed in the following issue:

    http://redmine.ruby-lang.org/issues/show/2294

    Regards,
    Ammar
     
    Ammar Ali, Dec 7, 2010
    #2
    1. Advertising

  3. Marc Weber

    Marc Weber Guest

    Excerpts from Ammar Ali's message of Tue Dec 07 01:32:12 +0100 2010:
    > Is this a multithreaded environment? If so, it sounds vaguely like the
    > problem discussed in the following issue:
    > http://redmine.ruby-lang.org/issues/show/2294


    Wow. I can reproduce the bug by running the initialization code within a
    pthread easily now.

    Does anybody know which is the correct solution?

    I'm protecting ruby by using mutexes - so only one thread will be
    evaluating ruby code at any given time.

    Where can I find the documentation how to embed Ruby in a multithreaded
    environment then?

    Marc Weber
     
    Marc Weber, Dec 7, 2010
    #3
  4. Marc Weber

    Ammar Ali Guest

    On Tue, Dec 7, 2010 at 3:26 AM, Marc Weber <> wrote:
    > Excerpts from Ammar Ali's message of Tue Dec 07 01:32:12 +0100 2010:
    >> Is this a multithreaded environment? If so, it sounds vaguely like the
    >> problem discussed in the following issue:
    >> =C2=A0http://redmine.ruby-lang.org/issues/show/2294

    >
    > Wow. I can reproduce the bug by running the initialization code within a
    > pthread easily now.
    >
    > Does anybody know which is the correct solution?
    >
    > I'm protecting ruby by using mutexes - so only one thread will be
    > evaluating ruby code at any given time.


    Mutexes won't help with this problem. The issue here is the GC is not
    able to tell where the top of the stack is. If possible, the best
    solution is to initialize ruby from main(), that way the GC can figure
    out where the stack starts. If that's not possible, as in the case of
    a dynamically loadable module, the patch submitted by Suraj Kurapati
    in the issue above is worth trying out. Even though it is not
    guaranteed to work, it worked for some. The patch basically adds a new
    function to ruby that allows the stack bounds to be updated at
    runtime. See the fifth note, by Roman Shterenzon, for how to get the
    stack bounds of a pthread.

    Regards,
    Ammar
     
    Ammar Ali, Dec 7, 2010
    #4
  5. Marc Weber

    Marc Weber Guest

    Excerpts from Ammar Ali's message of Tue Dec 07 03:24:55 +0100 2010:
    > guaranteed to work, it worked for some.

    Ok thanks. I definitely don't understand all details at this moment.

    I'm surprised that such a popular language such as Ruby causes that much
    trouble to me in this particular case.

    I'm going to try the patch fearing that its causing kind of trouble to
    me later :)

    Thank you for your help.

    Marc Weber
     
    Marc Weber, Dec 7, 2010
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JKop
    Replies:
    10
    Views:
    975
  2. Pieter Claassen

    libpcap: segfault on free after calloc

    Pieter Claassen, Aug 3, 2004, in forum: C Programming
    Replies:
    3
    Views:
    801
    -berlin.de
    Aug 3, 2004
  3. Matthias Kaeppler
    Replies:
    2
    Views:
    465
    Victor Bazarov
    Jul 18, 2005
  4. Replies:
    6
    Views:
    476
    Ron Natalie
    Dec 11, 2005
  5. Andrey Vul
    Replies:
    8
    Views:
    710
    Richard Bos
    Jul 30, 2010
Loading...

Share This Page