# Ruby and networking crashes app on windows

**URL:** <https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361>\
**Category:** Ruby\
**Created:** [April 5, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361 "2010-04-05T20:19:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 5, 2010, 8:19pm UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/1 "2010-04-05T20:19:21Z")

</div>

Hi!

It’s been quite long since I last posted here, but now I feel I’m stuck.

What I’m trying is to embed a ruby interpreter into a (multi-threaded)  
3rd party app (using its scripting interface and its ability to load  
DLLs through it), and run my ruby code by it. After much trial and  
error, I’ve managed to have it work to the extent that I can call into  
my own ruby code without having it crash the app.

However, anytime I try to access any networking abilities from ruby, it  
crashes the host app immediately, with a MS Visual C++ Runtime dialog  
telling me that it’s requested to terminate the app in an unusual way,  
and a sole OK button. There’s no logs, standard output, anything.

Does anyone have some insight as to how I could circumvent this problem?

Some details: I’m trying to embed MRI ruby 1.8.7 (2008-08-11 patchlevel  
72) [i386-mswin32] through a DLL compiled using MinGW gcc on WinXP SP2,  
and tried to run it on SP3.

thx in advance  
mortee

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 7, 2010, 12:48am UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/2 "2010-04-07T00:48:24Z")

</div>

> Some details: I’m trying to embed MRI ruby 1.8.7 (2008-08-11 patchlevel  
> 72) [i386-mswin32] through a DLL compiled using MinGW gcc on WinXP SP2,  
> and tried to run it on SP3.

How about the rubyinstaller version?  
-rp

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 8, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/3 "2010-04-08T21:21:09Z")

</div>

On 04/07/2010 00:48, Roger P. wrote:

> > Some details: I’m trying to embed MRI ruby 1.8.7 (2008-08-11 patchlevel  
> > 72) [i386-mswin32] through a DLL compiled using MinGW gcc on WinXP SP2,  
> > and tried to run it on SP3.
> 
> How about the rubyinstaller version?  
> -rp

I’ve tried using the latest versions from the rubyinstaller page, though  
not the self-installing versions, but the 7zip stuff. It still crashes  
using both of these:

ruby 1.8.7 (2010-01-10 patchlevel 249) [i386-mingw32]  
ruby 1.9.1p378 (2010-01-10 revision 26273) [i386-mingw32]

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 8, 2010, 10:47pm UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/4 "2010-04-08T22:47:11Z")

</div>

> Does anyone have some insight as to how I could circumvent this problem?

Make sure to run your ruby code in only one thread at a time and only  
from the “main” thread (?)

You could post backtraces, as well.  
-rp

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 9, 2010, 1:03am UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/5 "2010-04-09T01:03:36Z")

</div>

> Make sure to run your ruby code in only one thread at a time and only  
> from the “main” thread (?)

Well, I’m making sure to call it from a single thread, but I can’t force  
to do it from the main one. I’m writing an extension for a 3rd party  
app, which calls my code from whatever thread it wants to, and it’s  
definitely not the main one.

> You could post backtraces, as well.

I’d be glad to, but as I’ve said already, I have no logs (at least not  
at this level), and no terminal output from the app involved. All I get  
is a dialog window from the MS Visual Runtime telling me about the  
crash, without any usable details.

The weird part is that non-network code (even usong multiple ruby  
threads) runs without problems.

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 8, 2010, 10:36pm UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/6 "2010-04-08T22:36:06Z")

</div>

On 4/5/10, mortee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What I’m trying is to embed a ruby interpreter into a (multi-threaded)  
> 3rd party app (using its scripting interface and its ability to load  
> DLLs through it), and run my ruby code by it. After much trial and  
> error, I’ve managed to have it work to the extent that I can call into  
> my own ruby code without having it crash the app.
> 
> However, anytime I try to access any networking abilities from ruby, it  
> crashes the host app immediately, with a MS Visual C++ Runtime dialog  
> telling me that it’s requested to terminate the app in an unusual way,  
> and a sole OK button. There’s no logs, standard output, anything.

This is just a wild guess, but it’s possible that embedding in a  
multi-threaded program is what gives you grief. Suraj Kurapatni (sp?)  
was having problems with it a while ago. I don’t remember the exact  
details, but it seems that ruby likes the stack(s) to be where _it_  
wants them to be… he eventually came up with some patches to let you  
at least tell ruby where the stacks actually are, but I don’t think  
they were accepted. I’d point you at the relevant bug report on  
redmine, but it’s seemingly down for repairs right now. ☹

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 9, 2010, 1:45am UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/7 "2010-04-09T01:45:45Z")

</div>

On Apr 8, 8:01 pm, mortee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > You could post backtraces, as well.
> 
> I’d be glad to, but as I’ve said already, I have no logs (at least not  
> at this level), and no terminal output from the app involved. All I get  
> is a dialog window from the MS Visual Runtime telling me about the  
> crash, without any usable details.
> 
> The weird part is that non-network code (even usong multiple ruby  
> threads) runs without problems.

Is the application you’re embedding/calling ruby library compiled with  
a newer version of Microsoft C? Can you verify it links to MSVCRT and  
_not_ MSVCR80.DLL or MSVCR90.DLL?

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 9, 2010, 7:20pm UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/8 "2010-04-09T19:20:31Z")

</div>

On 4/8/10, mortee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Make sure to run your ruby code in only one thread at a time and only  
> > from the “main” thread (?)
> 
> Well, I’m making sure to call it from a single thread, but I can’t force  
> to do it from the main one. I’m writing an extension for a 3rd party  
> app, which calls my code from whatever thread it wants to, and it’s  
> definitely not the main one.

Calling out to the ruby interpreter from a program whose source you  
don’t control and not from the program’s main thread… definitely  
sounds dangerous. Now that redmine is back, I went and found the bug I  
mentioned before, but upon reading, that problems seems to have been  
with invoking ruby from the main thread only. So, it may not help you,  
directly, but maybe these bug reports will stimulate some ideas:

[http://redmine.ruby-lang.org/issues/show/2258](http://redmine.ruby-lang.org/issues/show/2258)  
[http://redmine.ruby-lang.org/issues/show/2294](http://redmine.ruby-lang.org/issues/show/2294)

> I’d be glad to, but as I’ve said already, I have no logs (at least not  
> at this level), and no terminal output from the app involved. All I get  
> is a dialog window from the MS Visual Runtime telling me about the  
> crash, without any usable details.

You need to get some visibility into this problem. Maybe you can run  
the program within a debugger, and extract a stack dump from that when  
it crashes?

---

<div class="post-metadata">

**Author:** ![mortee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/50afbb/32.png) [@mortee](https://www.ruby-forum.com/u/mortee)\
**Post date:** [April 9, 2010, 3:15am UTC](https://www.ruby-forum.com/t/ruby-and-networking-crashes-app-on-windows/186361/9 "2010-04-09T03:15:54Z")

</div>

> Is the application you’re embedding/calling ruby library compiled with  
> a newer version of Microsoft C? Can you verify it links to MSVCRT and  
> _not_ MSVCR80.DLL or MSVCR90.DLL?

It seems to load both msvcrt.dll and msvcr80.dll, even before hitting  
any of my code. It also loads msvcp80.dll, for that matter.

mortee
