Why am I getting an OpenSSL::SSL::SSLError only on Windows? - ruby

I'm downloading files from a HTTPS website. I've narrowed the problem down to this:
>> require 'open-uri'
>> open('https://www.gmail.com/') # just as an example
C:/Ruby/lib/ruby/1.8/net/http.rb:586:in `connect': certificate verify failed (OpenSSL::SSL::SSLError)
from C:/Ruby/lib/ruby/1.8/net/http.rb:586:in `connect'
from C:/Ruby/lib/ruby/1.8/net/http.rb:553:in `do_start'
from C:/Ruby/lib/ruby/1.8/net/http.rb:542:in `start'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:242:in `open_http'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:162:in `catch'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:518:in `open'
from C:/Ruby/lib/ruby/1.8/open-uri.rb:30:in `open'
from openuri_sandbox.rb:3
This code works just fine on Mac OS X or Linux, but it just started failing on Windows. I've tested on a few Win XP installations and one Win 7 installation -- they all fail. They're all running Ruby 1.8.6 patchlevel 287. What's going on here? We know we can turn off SSL verification and it works (or at least seems to), but that seems like a poor solution.
I'm interfacing with the website in question using Mechanize, so I'd like to be able to continue to use that.
Update: It looks like the problem with Mechanize might be specific to Windows 7, unlike I previously thought. It worked just a couple of weeks ago, though.
Update 2: This is still happening on Windows (XP and 7), but not on Linux. It's no longer a problem in the important script I needed to make work, though -- still not sure why.

appears it happens because ruby doesn't ship with certificates? http://betterlogic.com/roger/2011/08/github-jruby-ssl-woe/

Could the difference be 32-bit vs 64-bit architecture?

I'm seeking the same solution myself. I resolved this issue on the command line using cURL and the information to set-up a CA-bundle. I'm still looking for a Ruby fix.
This is a common issue across on Linux, Windows, Windows, Mac, Ruby 1.8, Ruby 1.9 and JRuby from my testing/experiments.

Related

Ruby FileUtils.rm_r fails on Windows when there are symlinks to directories: alternatives?

I support a cross-platform ruby 2 script that works for OS X and Linux, but fails on Windows when it tries to remove a tree containing directory symlinks. Here's what I see in the simplest possible example, running from irb. The directory "parent" contains a symlink named "symlink" that points at a target directory. The target exists.
irb(main):001:0> require 'fileutils'
=> true
irb(main):003:0> FileUtils.rm_r 'parent'
Errno::ENOENT: No such file or directory - parent/symlink
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1349:in `open'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1349:in `entries'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1349:in `entries'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1536:in `postorder_traverse'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1537:in `block in postorder_traverse'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1536:in `each'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:1536:in `postorder_traverse'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:837:in `remove_entry'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:695:in `block in rm_r'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:691:in `each'
from c:/engapps/Ruby/lib/ruby/2.0.0/fileutils.rb:691:in `rm_r'
Outside of solutions like system('rmdir /s/q parent'), are there any other options here? I know that FileUtils.symlink() is unsupported on Windows, but a hardcore failure of FileUtils.rm_r() is something else entirely. This has been a problem since Win 7 came out, maybe even back to Vista, and I haven't found a good solution that doesn't involve shelling out to CMD.EXE.
NOTE: FileUtils.rm_rf() doesn't improve things.
I've read the source code for fileutils.rb in ruby 2.0, as well as code it depends on. It's abundantly clear from this source that Windows symlinks are not considered, although there is code that behaves differently for Win32 than for non-Windows all over this module. There don't seem to be any open tickets for Ruby regarding Windows symlinks, so the answer is, Ruby doesn't handle it and it doesn't look like it will anytime soon. So the system('rmdir /s/q parent') workaround is the way to remove a Windows directory tree containing symlinks.

Package app in Shoes4

I used Shoes4 to make a GUI for my ruby app. Now I'm packaging this app, but something's wrong.
I followed this https://github.com/shoes/shoes4 to package.
'rake gem' gave me:
rake aborted!
No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb)
org/jruby/RubyKernel.java:1081:in `load'
org/jruby/RubyKernel.java:1101:in `eval'
/Users/xxxxxxx/.rvm/gems/jruby-1.7.13/bin/jruby_executable_hooks:15:in `(root)'
(See full trace by running task with --trace)
'gem install pkg/shoes-4.0.0.pre1.gem' gave me:
ERROR: Could not find a valid gem 'pkg/shoes-4.0.0.pre1.gem' (>= 0) in any repository
'bin/shoes -p swt:app path/to/directory-of/your-shoes-app.rb' still packaged my app (I coded in a Mac). However, the app won't run on Macs and it said 'quit unexpectedly'. The funny thing is that the app runs well in a Windows 7.
Have I done something wrong? How am I supposed to make the app work on Macs?
Thanks in advance.
Packaging is still a baby and sadly breaks some times.
We fixed a couple of packaging bugs (especially some for Mac) in the last months. I'd welcome you to try again fresh from master of shoes.
If the problem persists, please open an issue over at Shoes4 so we can tackle it appropriately :)

Cannot preview Octopress generated website

I am new to Jekyll and I am trying to build a blog using static pages with Octopress.
rake is generating the site correctly without any errors but when I try to preview the site, depsite that the server starts without any error
>>> Compass is polling for changes. Press Ctrl-C to Stop.
[2014-02-23 15:23:50] INFO WEBrick 1.3.1
[2014-02-23 15:23:50] INFO ruby 2.0.0 (2013-11-22) [x64-mingw32]
[2014-02-23 15:23:50] INFO WEBrick::HTTPServer#start: pid=1996 port=4000
It will throw errors when I try to access localhost:4000 from my web browser and will not serve the files
127.0.0.1 - - [23/Feb/2014 15:25:25] "GET / HTTP/1.1" 200 - 0.0500
[2014-02-23 15:25:25] ERROR Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.
c:/Ruby/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `eof?'
c:/Ruby/lib/ruby/2.0.0/webrick/httpserver.rb:80:in `run'
c:/Ruby/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
I am running Windows 8.1 and I have been trying rake preview with both Ruby 1.9.3 and 2.0 and also both x86 and x64 architectures on different machines. Also I tried to disable my firewall but it did not fix the issue.
I'd really appreciate some help to solve this issue.
Thanks.
After some googling, it looks like this may be a WEBrick specific error with Windows and IE (you didn't list the browser(s) you tried, but most results also list IE as a culprit). I would try:
Hitting http://localhost:4000 from Firefox/Chrome and see if the error persists
Changing your default web server from WEBrick to something else (I'd recommend the Ruby Thin Server). An easy walkthrough specifically for Octopress and the Thin server can be found at this blog post.
From Octopress documentation, it is recommended that you use Ruby 1.9.3. You can easily get Ruby 1.9.3 and other useful tools for Windows system by installing railsInstaller.

Gitorious: git-poller won't start

I just installed a fresh gitorious on my server and wanted to test it when I found out that the git-poller didn't run. And it also didn't want to start.
I followed this guide: http://gitorious.org/gitorious/pages/DebianSqueezeInstallation, my system is Debian Squeeze and Ruby -v says ruby 1.8.7
Everything from that guide works so far. The system is up and running but I can't start the poller. All the poller writes into the logs is the following:
tmp/pids/poller.log
*** below you find the most recent exception thrown, this will be likely (but not certainly) the exception that made the application exit abnormally ***
#<MissingSourceFile: no such file to load -- user_auto_completions_helper>
*** below you find all exception objects found in memory, some of them may have been thrown in your application, others may just be in memory because they are standard exceptions ***
#<NoMemoryError: failed to allocate memory>
#<SystemStackError: stack level too deep>
#<fatal: exception reentered>
#<LoadError: no such file to load -- daemons>
#<TypeError: Expected a filter, an endpoint, a callable or a list of any of these.>
#<NameError: uninitialized constant ActiveMessaging>
#<MissingSourceFile: no such file to load -- user_auto_completions_helper>
tmp/pids/poller.output
/home/clients/client1/web85/web/vendor/rails/activesupport/lib/active_support/dependencies.rb:443:in `load_missing_constant': uninitialized constant ActiveMessaging (NameError)
from /home/clients/client1/web85/web/vendor/rails/activesupport/lib/active_support/dependencies.rb:80:in `const_missing'
from /home/clients/client1/web85/web/vendor/rails/activesupport/lib/active_support/dependencies.rb:92:in `const_missing'
from /home/clients/client1/web85/web/lib/gitorious/messaging/stomp_poller.rb:13
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons/application.rb:203:in `load'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons/application.rb:203:in `start_load'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons/application.rb:292:in `start'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons/controller.rb:70:in `run'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons.rb:143:in `run'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `catch_exceptions'
from /var/lib/gems/1.8/gems/daemons-1.1.0/lib/daemons.rb:142:in `run'
from script/poller:30
I'm using ispconfig as a webserver management tool, that's where the weird paths are from. I changed all paths from the howto to fit, tho.
Anybody got an idea? I can provide more material if needed, but I just don't know what could be usefull. This is my first question on stackoverflow so please don't shoot me if I didn't do everything right :)
After a lot of reading and trial and error (I started about 3 times from scratch, trying Ruby 1.9.2 and REE both from source and with RVM) I tried another howto[1] which had one big difference to the first one: It suggested downloading and installing Rubygems 1.4.2 instead of the apt-version of Rubygems.
At first I didn't want to do that because I was afraid that it would break my system (there are a lot of other things running on that server, including Redmine) which it did, but after I re-installed all missing gems everything worked again.
Now everything (Gitorious and Redmine) is working with apt-version of Ruby 1.8.7 and the non-apt-version of Rubygems 1.4.2.
[1] http://cjohansen.no/en/ruby/setting_up_gitorious_on_your_own_server/
Since I stumbled upon another, hopefully last problem:
I installed gitorious for my standard web user (in order to respect ISPConfig's policy) and made a new git-user for the repositories. To be able to exchange data I added both to the same usergroup and fixed the permissions.
The problem I ran into was that the git poller added new repositories for his own, that means "git:git" instead of "git:sharedgroup". To fix this you just have to set the default group id for the git-folder (/var/git in my case):
chgrp -R <group_name> /var/git
chmod -R g+s /var/git
It appears that the two commands above did work but adding a new project broke everything again because the git-poller added a folder for the project and the repository which resulted in the repository-folder having the wrong owner again.
I (hopefully) fixed that with changing my /etc/init.d/git-poller script from
/bin/su - git -c "cd /var/www/git.mydomain.com/web;RAILS_ENV=production script/poller $#"
to
/bin/su - git -c "newgrp <group_name> && cd /var/www/git.mydomain.com/web;RAILS_ENV=production script/poller $#"

Library `fcntl' can not be loaded on Solaris/Weblogic (JRuby 1.6.1) -> NullPointerException

While trying to deploy a JRuby/Rails Application to a Weblogic 10.3 (Solaris Zone) container it always encounters this exception:
org.jruby.rack.RackInitializationException: library `fcntl' could not be loaded: java.lang.NullPointerException
from /xyz/war/WEB-INF/gems/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:239:in `require'
from /xyz/war/WEB-INF/gems/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:225:in `load_dependency'
from /xyz/war/WEB-INF/gems/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:596:in `new_constants_in'
from /xyz/war/WEB-INF/gems/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:225:in `load_dependency'
from /xyz/war/WEB-INF/gems/gems/activesupport-3.0.6/lib/active_support/dependencies.rb:239:in `require'
from /xyz/war/WEB-INF/gems/gems/jruby-openssl-0.7.3/lib/openssl/ssl.rb:19:in `(root)'
from org/jruby/RubyKernel.java:1038:in `require'
[..snip...]
It just don't get it why JRuby fails to load this core library. It seems somehow Solaris related, because installing WLS on MacOS X and deploying locally works without any issues.
Any hints, or pointers where I can look next - or how to solve this issue?
UPDATE:
Probably a bug (got feedback in IRC/#jruby now tracked in JRuby JIRA, see: http://jira.codehaus.org/browse/JRUBY-5753
I solved this issue by adding -d32 to JAVA_OPTS, to force the use of a 32-bit JVM.
I was experiencing this problem on Centos 5 and OSX with Tomcat 7 and Jruby 1.7.2. and a sqlite3 db.
I resolved the issue through poking around and I'm not sure why what I did solved it but I discovered a few things:
I got this error after restarting Tomcat due to a previous crash which left the DB locked.
ActiveRecord::StatementInvalid (Java::JavaLang::Error: Internal Error in _syscall(): SELECT "urls".* FROM "urls" ):
The following steps seemed to resolve the issue, though it seems to me that the original error simply indicates that the DB got into a bad state.
-I downgraded Jruby to 1.7.1
-I removed all gems pertaining to the db from the gemfile except activerecord-jdbcsqlite3-adapter'. This seemed to resolve this issue. (The gems I removed were 'sqlite-ruby','sqlite3','activerecord-jdbc-adapter', 'jruby-rack') I note that the first gem here was a normal C gem, which shouldn't have been deployed because it wasn in a conditional but seemed to be getting included in the war by warbler anyway.
Anyway, I redeployed and it worked, even using the original DB.

Resources