Category: Hosting

Ruby 1.9.3 + OpenSSL::SSL::SSLError issue

Problem

OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv3
read server certificate B: certificate verify failed
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in
`connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in
`block in connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:68:in
`timeout'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99:in
`timeout'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799:in
`connect'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755:in
`do_start'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:750:in
`start'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/xmlrpc/client.rb:535:in
`do_rpc'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/xmlrpc/client.rb:420:in
`call2'
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/xmlrpc/client.rb:410:in
`call'
from /path/infusionsoft/connection.rb:15:in
`connection'
from /path/infusionsoft/request.rb:29:in
`request'
from /path/infusionsoft/request.rb:5:in
`get'
from /path/infusionsoft/client/contact.rb:59:in
`contact_find_by_email'
from /path/infusionsoft.rb:18:in
`method_missing'
from (irb):2
from /path/rails/commands/console.rb:45:in
`start'
from /path/rails/commands/console.rb:8:in
`start'
from /path/rails/commands.rb:40:in
`<top (required)>'
from ./script/rails:6:in `require'
from ./script/rails:6:in

Solution

To work this around, we need to overwrite use_ssl method:

module Net
  class HTTP
    def use_ssl=(flag)
      flag = flag ? true : false
      if started? and @use_ssl != flag
        raise IOError, "use_ssl value changed, but session already started"
      end
      @use_ssl = flag
      if @use_ssl
        self.verify_mode = OpenSSL::SSL::VERIFY_NONE
      end
    end
  end
end

Slowing down (limiting) tar, mysqldump or other processes to save IO bandwidth

Sometimes we want to perform some sort of tasks that consume whole available IO bandwidth. This may lead to some unexpected behaviours from our OS. OS might even kill the given process due to resource lack.

Lets take an example. We want to tar.gz a huge directory with a lot of files in it. Our machine also have a web-server which serves several sites. If we start "taring" our directory, it might lead to timeouts on server (it won't be able to respond as fast as we would expect). On the other hand, we don't care so much about the time needed to create archive file. We always can throw it in screen and detach it.

# Standard approach - will slow IO response time
tar -cvf ./dir.tar ./dir

pv to the rescue!

To slow things down to a tolerable level we will use pv tool. pv allows a user to see the progress of data through a pipeline, by giving information such as time elapsed, percentage completed (with progress bar), current throughput rate, total data transferred, and ETA. It can also limit the speed of incoming data, if used wisely.

To tar a file with a given speed (in MB) we need to use following command:

tar -chf - ./dir | pv -L 2m > ./dir.tar

Above example will allow us to tar ./dir with max speed 2MB/s.

We could use the same method to slow down a mysqldump method:

mysqldump --add-drop-table -u user -p password -h host db_name | bzip2 -c > ./dump.sql.bz2

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑