Tuesday, 12 April 2016

Open ssl crashes while Compiling Ruby 1.9.3p194 from source code

Once, I tried to compile ruby from source code using thin server. Problem occured when i tried to start thin with ssl option by specifying :-

ruby bin/thin --ssl -a 127.0.0.1 -p 44466 start

It started the server, but on accessing the https://localhost:44466. Ruby got crashed and gave the error on console with a popup on windows saying ruby interpretor has stopped working.

"This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information."

And what I could see n windows logs was:--

Faulting application name: ruby.exe, version: 1.9.3.194, time stamp: 0x5154804d
Faulting module name: MSVCR90.dll, version: 9.0.30729.4940, time stamp: 0x4ca2ef57
Exception code: 0x40000015
Fault offset: 0x0005beae
Faulting process id: 0x11d4
Faulting application start time: 0x01cf7fb6cca849aa
Faulting application path: C:\Ruby19\bin\ruby.exe
Faulting module path: C:\Windows\WinSx\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_50916076bcb9a742\MSVCR90.dll
Report Id: 47c368b9-ebaa-11e3-8cd8-8c89a5d53bc0`


I compiled ruby with diff versions of openssl, but result was same application crash error. 

It was on windows platform and ruby was compiled using microsoft visual studio8. 
Below are details to be more specific.
platform :- windows7
compiler :- Microsoft visual studio9
Ruby :- ruby1.9.3p194
Openssl :- openssl 1.0.0d/openssl 1.0.0e

After multiple attempt, I decided to discuss thi back with bigger community, So I added this as defect in Ruby forum, Where after several discussion, Cam to know that culprit was eventmachine gem which comes as dependent gem with Thin.


The crash occurred in the following line of ed.cpp of eventmachine gem.
    #ifdef WITHOUT_SSL
    throw std::runtime_error ("Encryption not available on this event-machine");
    #endif
The eventmachine gem was built with WITHOUT_SSL macro on MSVC Compiler.
Here is a patch for eventmachine/ext/extconf.rb
diff --git a/extconf.rb b/extconf.rb.new
index 448802a..27a5b8b 100644
--- a/extconf.rb
+++ b/extconf.rb.new
@@ -25,7 +25,7 @@ end
 def manual_ssl_config
   ssl_libs_heads_args = {
     :unix => [%w[ssl crypto], %w[openssl/ssl.h openssl/err.h]],
-    :mswin => [%w[ssleay32 eay32], %w[openssl/ssl.h openssl/err.h]],
+    :mswin => [%w[ssleay32 libeay32], %w[openssl/ssl.h openssl/err.h]],
   }

   dc_flags = ['ssl']


Conclusion: This was a Third Party's Issue.

So I Build gem for editing with chnages suggested above, And whoa, It worked finally!!!
cd C:\Ruby19\lib\ruby\gems\1.9.1\gems\eventmachine-1.0.3\ext
edit extconf.rb as above
>ruby extconf.rb
>nmake
>copy rubyeventmachine.so C:\Ruby19\lib\ruby\gems\1.9.1\gems\eventmachine-1.0.3\lib