Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   embedding ruby - segfault after initialization when runningrb_gc_start?? (http://www.velocityreviews.com/forums/t865494-embedding-ruby-segfault-after-initialization-when-runningrb_gc_start.html)

Marc Weber 12-06-2010 04:47 PM

embedding ruby - segfault after initialization when runningrb_gc_start??
 
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


Ammar Ali 12-07-2010 12:32 AM

Re: embedding ruby - segfault after initialization when runningrb_gc_start??
 
On Mon, Dec 6, 2010 at 6:47 PM, Marc Weber <marco-oweber@gmx.de> 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


Marc Weber 12-07-2010 01:26 AM

Re: embedding ruby - segfault after initialization when runningrb_gc_start??
 
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


Ammar Ali 12-07-2010 02:24 AM

Re: embedding ruby - segfault after initialization when runningrb_gc_start??
 
On Tue, Dec 7, 2010 at 3:26 AM, Marc Weber <marco-oweber@gmx.de> 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


Marc Weber 12-07-2010 01:32 PM

Re: embedding ruby - segfault after initialization when runningrb_gc_start??
 
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



All times are GMT. The time now is 09:58 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.