Wednesday, January 27, 2010

ruby 1.9 libs, openssl

yet another problem solved:

ledZeppelin% ./minimal.rb
/usr/lib/ruby/1.9.0/net/smtp.rb:197:in `default_ssl_context': uninitialized constant Net::SMTP::OpenSSL (NameError)
from /usr/lib/ruby/1.9.0/net/smtp.rb:342:in `enable_starttls'
from ./minimal.rb:24:in `_send_email'
from ./minimal.rb:33:in `
'
ledZeppelin% #futz around with gem1.9 looking for the obvious ssl package
ledZeppelin% aptitude search ssl|grep -i ruby
p libopenssl-ruby - OpenSSL interface for Ruby
i A libopenssl-ruby1.8 - OpenSSL interface for Ruby 1.8
p libopenssl-ruby1.9 - OpenSSL interface for Ruby 1.9
p libopenssl-ruby1.9.1 - OpenSSL interface for Ruby 1.9.1
ledZeppelin% sudo aptitude install libopenssl-ruby1.9
[sudo] password for danny:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
The following NEW packages will be installed:
libopenssl-ruby1.9
0 packages upgraded, 1 newly installed, 0 to remove and 15 not upgraded.
Need to get 133kB of archives. After unpacking 979kB will be used.
Writing extended state information... Done
Get:1 http://us.archive.ubuntu.com karmic/universe libopenssl-ruby1.9 1.9.0.5-1ubuntu1 [133kB]
Fetched 133kB in 1s (121kB/s)
Selecting previously deselected package libopenssl-ruby1.9.
(Reading database ... 212364 files and directories currently installed.)
Unpacking libopenssl-ruby1.9 (from .../libopenssl-ruby1.9_1.9.0.5-1ubuntu1_amd64.deb) ...
Setting up libopenssl-ruby1.9 (1.9.0.5-1ubuntu1) ...
Reading package lists... Done
Building dependency tree
Reading state information... Done
Reading extended state information
Initializing package states... Done
Writing extended state information... Done
ledZeppelin% uname -a
Linux ledZeppelin 2.6.31-17-generic #54-Ubuntu SMP Thu Dec 10 17:01:44 UTC 2009 x86_64 GNU/Linux
ledZeppelin% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 9.10
Release: 9.10
Codename: karmic
ledZeppelin% ./minimal.rb
ledZeppelin% #email in my inbox, yay


and that was it

be careful with ruby include

turns out the problem i've been having over the last few days has been that i included some libs in the top level of a ruby file. so the module's definition of "read" overrode the kernel's version. as you might suspect, changing ruby's idea of "read" around leads to errors. in my case, the first code to hit this was inside a soap library, which called an http library. so i thought the problem might be in there. i spent yesterday and today tracking that error down. i did other things during that time, but still that was lots of time.

i tracked it down by creating a minimal test case for the soap portion, iprofiletools.rb, creating a class out of it and having a small driver at the end of the class definition file: if $0 == __FILE__ then driver_code end.
when that worked, but using the class in the project still yielded errors, i knew it wasn't the soap code that was bad. i suspected global variables or constants set in the module might be messing with some setting used somewhere down the line.
so i tried putting in all the includes from vue_monitor.rb to the top of iprofiletools.rb.
this reproduced the errors i saw when running vue_monitor.rb. since i didn't actually need any of those "require"s and "include"s, i started removing them and rerunning iprofiletools until i had a minimal set that created the error. that led me to SimpleCommons
i looked in SimpleCommons for globals and constants and found nothing obvious. so i started commenting out large portions and rerunning iprofiletools. eventually i narrowed it down to the read function.
that's when i realized that i was "include"ing SimpleCommons at the top level. all i needed to do was include it within the class, instead of at the top level, directly into Kernel.
that's a better model of what i want anyways. i want the stuff in SimpleCommons to be a part of the Vue_Monitor class, not a part of Kernel.

i'm not sure how this problem didn't come up earlier. git bisect would have been a better approach to this. i could have seen the diff that started this all. but the problem only appeared on one machine and not on my laptop. so i initially started with the suspicion that the installed library was the culprit. i'm still not sure why errors only produced on one machine and not the other.

anywho. i've fixed it. i understand part of what was wrong. i know now to be careful with includes.

Where am I?