embedding ruby - segfault after initialization when runningrb_gc_start??

M

Marc Weber

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
 
A

Ammar Ali

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
 
M

Marc Weber

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
 
A

Ammar Ali

Excerpts from Ammar Ali's message of Tue Dec 07 01:32:12 +0100 2010:

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
 
M

Marc Weber

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top