Ruby 1.9.2, EventMachine 0.12.10, and SSL

1,896 views
Skip to first unread message

Steve Shreeve

unread,
Aug 20, 2010, 5:55:52 AM8/20/10
to RubyInstaller
Luis, et. al.,

Congrats on the tremendous work towards a turn-key Ruby installer on
Windows!

I'm currently using the following components:

* Ruby 1.9.2 - using latest rubyinstaller GitHub repo (needed
"autocrlf=false" in my .gitconfig)
* EventMachine - using latest GitHub repo (standard gem fails to
install)
* em-http-request - using standard gem

The following code works great:

require 'em-http-request'

EventMachine.run {
http = EventMachine::HttpRequest.new(
'http://www.google.com/'
).get

http.callback {
p http.response_header.status
p http.response_header
p http.response

EventMachine.stop
}
}

However, if the URL is changed to https, such as:

'https://www.53.com/wps/portal/personal'

then, I see the following error:

--

terminate called after throwing an instance of 'std::runtime_error'
what(): Encryption not available on this event-machine

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

--

After much fiddling, I was unable to get EventMachine to compile the
SSL libraries. However, I see that openssl was already compiled when I
originally compiled Ruby 1.9.2 using the rubyinstaller.

Is there any way to simply use the already compiled DLL's and existing
header files that are on my system from when I compiled Ruby 1.9.2?
I'd be happy to ask on the EventMachine list also, but since the
rubyinstaller compiled and/or copied these files, I figured I might
ask here first.

Given the importance of EventMachine and the putative rush of people
wanting to explore 1.9.2, it seems fairly critical that there be out
of the box support for https.

Let me know if this question would be better taken elsewhere.

Thanks,

Steve

Luis Lavena

unread,
Aug 20, 2010, 7:51:20 AM8/20/10
to rubyin...@googlegroups.com
On Fri, Aug 20, 2010 at 6:55 AM, Steve Shreeve <steve....@gmail.com> wrote:
> Luis, et. al.,
>

Hello Steve,

> Congrats on the tremendous work towards a turn-key Ruby installer on
> Windows!
>
> I'm currently using the following components:
>
> * Ruby 1.9.2 - using latest rubyinstaller GitHub repo (needed
> "autocrlf=false" in my .gitconfig)
> * EventMachine - using latest GitHub repo (standard gem fails to
> install)

Yes, I believe there are some changes and previous conversations here
about 1.9.2

> * em-http-request - using standard gem
>
> The following code works great:
>
> require 'em-http-request'
>
> EventMachine.run {
>  http = EventMachine::HttpRequest.new(
>    'http://www.google.com/'
>  ).get
>
>  http.callback {
>    p http.response_header.status
>    p http.response_header
>    p http.response
>
>    EventMachine.stop
>  }
> }
>
> However, if the URL is changed to https, such as:
>
>    'https://www.53.com/wps/portal/personal'
>
> then, I see the following error:
>
> --
>
> terminate called after throwing an instance of 'std::runtime_error'
>  what():  Encryption not available on this event-machine
>

The problem is that EventMachine for SSL is trying to link and use
OpenSSL, and is not there. It needs OpenSSL development headers and
such.

As a workaround, you can try building and installing EventMachine
against sandbox/openssl:

gem install eventmachine -- --with-openssl-dir=....

If you check extconf.rb of EM I believe that is supported, or should
be if not :-)

>
> After much fiddling, I was unable to get EventMachine to compile the
> SSL libraries. However, I see that openssl was already compiled when I
> originally compiled Ruby 1.9.2 using the rubyinstaller.
>
> Is there any way to simply use the already compiled DLL's and existing
> header files that are on my system from when I compiled Ruby 1.9.2?

Oops, need to read the full email before replying, see above :-)

> I'd be happy to ask on the EventMachine list also, but since the
> rubyinstaller compiled and/or copied  these files, I figured I might
> ask here first.
>
> Given the importance of EventMachine and the putative rush of people
> wanting to explore 1.9.2, it seems fairly critical that there be out
> of the box support for https.

postgres ruby bindings developers decided to use rake-compiler
cross-compiling approach to build openssl statically and link against
it.

I believe EventMachine guys could take that and implement it to
distribute a native gem for Windows.

> Let me know if this question would be better taken elsewhere.
>

It is the right place to ask, and thank you for doing your homework
and investigating the issue. However, we might not have the control or
the manpower to change every gem out there to make it more easy to
support Windows.

Hope my answer somehow helps.

Cheers,
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Steve Shreeve

unread,
Aug 20, 2010, 1:29:56 PM8/20/10
to RubyInstaller
Luis,

Success!!!

I now have Ruby 1.9.2 on Windows with a clean, working, latest github
version of EventMachine running with OpenSSL support (so that https
requests finally work!).

> The problem is that EventMachine for SSL is trying to link and use
> OpenSSL, and is not there. It needs OpenSSL development headers and
> such.

Fortunately, when using rubyinstaller to build Ruby 1.9.2, these
libraries and header files are either compiled or otherwise made
available on the local machine. The question is how do we simply refer
to them when compiling EventMachine?

> As a workaround, you can try building and installing EventMachine
> against sandbox/openssl:
>
> gem install eventmachine -- --with-openssl-dir=....

This is very close, but it actually wanted "--with-ssl-dir..." instead
of "--with-openssl-dir=...".

NOTE: In order for the below to work, I had to first clone the github
repository for rubyinstaller. Using that, I compiled and installed a
fresh Ruby 1.9.2 (using 'rake ruby19') and DevKit (using 'rake devkit
SFX=1' and then installed the "DevKit-4.5.0-{timestamp}-sfx.exe" file
it generates). There's a little setup required to get DevKit properly
configured (see the Wiki on the rubyinstaller project, where DevKit is
described).

Without further ado, here's what I did to get EventMachine running on
Ruby 1.9.2 on Windows with SSL support:

D:\Code\Gems>git clone http://github.com/eventmachine/eventmachine.git
Cloning into eventmachine...
remote: Counting objects: 3404, done.
remote: Compressing objects: 100% (1195/1195), done.
remote: Total 3404 (delta 2454), reused 2976 (delta 2084)
Receiving objects: 100% (3404/3404), 701.70 KiB | 423 KiB/s, done.
Resolving deltas: 100% (2454/2454), done.

D:\Code\Gems>cd eventmachine

D:\Code\Gems\eventmachine>gem build eventmachine.gemspec
Successfully built RubyGem
Name: eventmachine
Version: 0.12.11
File: eventmachine-0.12.11.gem

D:\Code\Gems\eventmachine>gem install eventmachine-0.12.11.gem -- --
with-ssl-dir=d:/Code/rubyinstaller/sandbox/openssl
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed eventmachine-0.12.11
1 gem installed

D:\Code\Gems\eventmachine>gem install em-http-request
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
Successfully installed em-http-request-0.2.11
1 gem installed

D:\Code\Gems\eventmachine>ruby bank.rb
200
{"DATE"=>"Fri, 20 Aug 2010 17:09:03 GMT",
"SERVER"=>"IBM_HTTP_Server", ... the rest of the request!

The source for bank.rb is:

require 'em-http-request'

EventMachine.run {
http = EventMachine::HttpRequest.new(
'https://www.53.com/wps/portal/personal'
).get

http.callback {
p http.response_header.status
p http.response_header
p http.response

EventMachine.stop
}
}

I hope this is helpful to others. Also, I hope the EventMachine
maintainers update the standard rubygems version soon so that it works
with Ruby 1.9.2 on Windows.

> It is the right place to ask, and thank you for doing your homework
> and investigating the issue. However, we might not have the control or
> the manpower to change every gem out there to make it more easy to
> support Windows.

I agree. EventMachine is such an important gem, however, that it might
warrant a little extra attention. Hopefully, we're good to go from now
on!

> Hope my answer somehow helps.

Thanks Luis for all of your help!

Cheers,

Steve

Luis Lavena

unread,
Aug 20, 2010, 2:20:08 PM8/20/10
to rubyin...@googlegroups.com
On Fri, Aug 20, 2010 at 2:29 PM, Steve Shreeve <steve....@gmail.com> wrote:
> Luis,
>
> Success!!!
>
> I now have Ruby 1.9.2 on Windows with a clean, working, latest github
> version of EventMachine running with OpenSSL support (so that https
> requests finally work!).
>

Excellent.

>> The problem is that EventMachine for SSL is trying to link and use
>> OpenSSL, and is not there. It needs OpenSSL development headers and
>> such.
>
> Fortunately, when using rubyinstaller to build Ruby 1.9.2, these
> libraries and header files are either compiled or otherwise made
> available on the local machine. The question is how do we simply refer
> to them when compiling EventMachine?
>

You mean by gem installation?

The headers and libs are not available out of the sandbox, you need to
refer to them, that is the only way.

>> As a workaround, you can try building and installing EventMachine
>> against sandbox/openssl:
>>
>> gem install eventmachine -- --with-openssl-dir=....
>
> This is very close, but it actually wanted "--with-ssl-dir..." instead
> of "--with-openssl-dir=...".
>

Ah, ok, never checked what options it really used or provided.

[snip of instructions]

> Thanks Luis for all of your help!
>

Thanks to you for your patience and not giving up. This (SSL for EM)
has been asked before and we never agreed on a solution for it.

Thank you for documenting it. Feel free to add a link to your
individual message in the wiki:

http://wiki.github.com/oneclick/rubyinstaller/tutorials

Jon

unread,
Aug 20, 2010, 2:33:48 PM8/20/10
to rubyin...@googlegroups.com
> D:\Code\Gems\eventmachine>gem install eventmachine-0.12.11.gem -- --
> with-ssl-dir=d:/Code/rubyinstaller/sandbox/openssl
> Temporarily enhancing PATH to include DevKit...
> Building native extensions. This could take a while...
> Successfully installed eventmachine-0.12.11
> 1 gem installed

Great info, thanks.

If you do decide to put a tutorial link to our wiki page as Luis mention, I suggest you include "--platform=ruby" to be more robust. This option is more robust as it forces the native gem to be compiled. This wasn't a problem in this case as neither eventmachine nor em-http-request has binary gems for the RubyInstaller (x86-mingw32). However, _if_ they did have a binary gem _and_ it only supported 1.8 rather than being a 1.8+1.9 "fat binary" gem, I would expect things to fail on 1.9.2. Luis may want to comment further.

> D:\Code\Gems\eventmachine>ruby bank.rb
> 200
> {"DATE"=>"Fri, 20 Aug 2010 17:09:03 GMT",
> "SERVER"=>"IBM_HTTP_Server", ... the rest of the request!
>
> The source for bank.rb is:


To confirm, this script ran successfully after you ran "rake clean" and removed the d:/Code/rubyinstaller/sandbox/openssl directory? I expect it should as I'm guessing your 1.9.2 Ruby "bin" dir is on PATH so eventmachine finds the libeay32-* and ssleay32-* DLLs at runtime.

Jon

Steve Shreeve

unread,
Aug 25, 2010, 1:56:01 PM8/25/10
to RubyInstaller
Jon,

> If you do decide to put a tutorial link to our wiki page as Luis mention, I suggest you include "--platform=ruby" to be more robust.  This option is more robust as it forces the native gem to be compiled.

Is there a way to make this the default if you have installed the
DevKit? That way, you wouldn't have to manually type it each time? I'm
not sure if it's possible to do, but it seems like it should be. Any
ideas?

> To confirm, this script ran successfully after you ran "rake clean" and removed the d:/Code/rubyinstaller/sandbox/openssl directory?  I expect it should as I'm guessing your 1.9.2 Ruby "bin" dir is on PATH so eventmachine finds the libeay32-* and ssleay32-* DLLs at runtime.

Sort of... I didn't run rake clean, but I did install two versions of
the eventmachine gem, one with SSL and one without it. I then compared
the gems directories to see what was different. I saw that the one
without SSL support includes an ssl.o file shows as being 1KB in size.
The one with SSL support shows as 79KB in size. I then deleted the
rubyinstaller directory completely and verified that everything still
works. As a result, I'm fairly certain that the ssl.o file in the gems
directory is being used, and not a reference to the library from the
sandbox.

Thanks,

Steve

Luis Lavena

unread,
Aug 25, 2010, 2:03:04 PM8/25/10
to rubyin...@googlegroups.com
On Wed, Aug 25, 2010 at 2:56 PM, Steve Shreeve <steve....@gmail.com> wrote:
> Jon,
>
>> If you do decide to put a tutorial link to our wiki page as Luis mention, I suggest you include "--platform=ruby" to be more robust.  This option is more robust as it forces the native gem to be compiled.
>
> Is there a way to make this the default if you have installed the
> DevKit? That way, you wouldn't have to manually type it each time? I'm
> not sure if it's possible to do, but it seems like it should be. Any
> ideas?
>

I will not recommend that. There are scenarios you will like to use
the binary gems instead of custom build ones.

nokogiri is one example, depends on things like libxml2 which are not
easily available under Windows (compatible with the same CRT, there
are other binaries but links against CRT 8.0 or 9.0)

>> To confirm, this script ran successfully after you ran "rake clean" and removed the d:/Code/rubyinstaller/sandbox/openssl directory?  I expect it should as I'm guessing your 1.9.2 Ruby "bin" dir is on PATH so eventmachine finds the libeay32-* and ssleay32-* DLLs at runtime.
>
> Sort of... I didn't run rake clean, but I did install two versions of
> the eventmachine gem, one with SSL and one without it. I then compared
> the gems directories to see what was different. I saw that the one
> without SSL support includes an ssl.o file shows as being 1KB in size.
> The one with SSL support shows as 79KB in size. I then deleted the
> rubyinstaller directory completely and verified that everything still
> works. As a result, I'm fairly certain that the ssl.o file in the gems
> directory is being used, and not a reference to the library from the
> sandbox.
>

Well, actually no. the ssl.o is the ssl.cpp compiled to object code
which is then linked along the other object files.

When there is no SSL headers, it generates the dummy .o (1KB) which is
still linked.

EventMachine requires to actually check for OpenSSL not just at
compilation but at execution, which is the one that generated the
segfault in the first place.

Anyhow, eventmachine.so will be linked against the shared objects
provided by RubyInstaller, which is safe.

Steve Shreeve

unread,
Aug 25, 2010, 2:46:43 PM8/25/10
to RubyInstaller
Luis,

> > Is there a way to make this the default if you have installed the
> > DevKit? That way, you wouldn't have to manually type it each time? I'm
> > not sure if it's possible to do, but it seems like it should be. Any
> > ideas?
>
> I will not recommend that. There are scenarios you will like to use
> the binary gems instead of custom build ones.

Ah... I see what you mean.

> Well, actually no. the ssl.o is the ssl.cpp compiled to object code
> which is then linked along the other object files.

I made a temporary little repo on github to show what I did to get SSL
support working for EventMachine using the stock Ruby 1.9.2p0
installer that you made. Essentially, I used the output from compiling
ruby 1.9.2 using the rubyinstaller from github and then just grabbed
the openssl include directory and two of the compiled files in the lib
directory to create a minimal set of files required for me to compile
and run an SSL-enabled EventMachine using the stock ruby 1.9.2p0
installer that you released. Here's the link to the temporary repo:

http://github.com/shreeve/openssl-0.9.8-minimum

Given that EventMachine is required for many other libraries (eg -
thin), it would be great to easily support it. What I have done in the
repo above works, but there must be a clean/correct way to do it.

Is there a better way to do this?

Thanks,

Steve

Luis Lavena

unread,
Aug 25, 2010, 3:33:01 PM8/25/10
to rubyin...@googlegroups.com
On Wed, Aug 25, 2010 at 3:46 PM, Steve Shreeve <steve....@gmail.com> wrote:
> Luis,

>
>
> I made a temporary little repo on github to show what I did to get SSL
> support working for EventMachine using the stock Ruby 1.9.2p0
> installer that you made. Essentially, I used the output from compiling
> ruby 1.9.2 using the rubyinstaller from github and then just grabbed
> the openssl include directory and two of the compiled files in the lib
> directory to create a minimal set of files required for me to compile
> and run an SSL-enabled EventMachine using the stock ruby 1.9.2p0
> installer that you released. Here's the link to the temporary repo:
>
>  http://github.com/shreeve/openssl-0.9.8-minimum
>

Nice

> Given that EventMachine is required for many other libraries (eg -
> thin), it would be great to easily support it. What I have done in the
> repo above works, but there must be a clean/correct way to do it.
>
> Is there a better way to do this?
>

postgresql guys use rake-compiler to cross compile also support
libraries like openssl for their gem:

http://bitbucket.org/ged/ruby-pg/src/tip/Rakefile.local

It can be cleaned up, but I've been working on a more ruby-friendly
library for these cases. I wish I had more time for OSS :-(

Reply all
Reply to author
Forward
0 new messages