Sandip Mane
by Sandip Mane
~1 min read

Categories

  • Ruby on Rails
  • Heroku

Tags

  • rails
  • ruby
  • heroku
  • redis

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=error: certificate verify failed (self signed certificate in certificate chain))

This error is occurring because Redis6 requires SSL to connect while Heroku does not use SSL, instead, they use HTTP routing.

This error will not occur for the hobby-dev verion of the Redis6 on Heroku as it supports both HTTP and HTTPS connections.

Fix

The fix suggested by Heroku involves changing the verification mode.

$redis = Redis.new(url: ENV["REDIS_URL"], ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE })

Fixes for Rails

1. If you are using Sidekiq

Sidekiq.configure_server do |config|
  config.redis = {
    url: ENV["REDIS_URL"],
    ssl_params: {
      verify_mode: OpenSSL::SSL::VERIFY_NONE
    }
  }
end

Sidekiq.configure_client do |config|
  config.redis = {
    url: ENV["REDIS_URL"],
    ssl_params: {
      verify_mode: OpenSSL::SSL::VERIFY_NONE
    }
  }
end

2. If you are using Redis Cache Store

config.cache_store = :redis_cache_store, {
  url: ENV["REDIS_URL"],
  ssl_params: {
    verify_mode: OpenSSL::SSL::VERIFY_NONE
  }
}

3. If you are using ActionCable

Add the last two lines of code to all the apps that are on Heroku in config/cable.yml.

# config/cable.yml

production:
  adapter: redis
  url: <%= ENV["REDIS_URL"] %>
  ssl_params:
    verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>

This should fix the issue in Rails!