Error in launcing app server in Heroku (And how to solve)
Environments
- Heroku
- Memcachier
- Rails 5 API Mode
- MySQL ClearDB
Error
2017-04-25T08:46:54.321621+00:00 app[web.1]: W, [2017-04-25T08:46:54.321561 #4] WARN -- : localhost:11211 failed (count: 0) Errno::ECONNREFUSED: Connection refused - connect(2) for "localhost" port 11211
source code (before resolve the problem)
configuration file
config.cache_store = :dalli_store,
nil,
{
:username => ENV["MEMCACHIER_USERNAME"],
:password => ENV["MEMCACHIER_PASSWORD"],
:failover => true,
:socket_timeout => 1.5,
:socket_failure_delay => 0.2,
:down_retry_delay => 60,
:expires_in => 7.day,
:compress => true,
:namespace => 'Planna-prod',
}
note: According to GitHub - petergoldstein/dalli: High performance memcached client for Ruby
If your servers are specified in ENV["MEMCACHE_SERVERS"] (e.g. on Heroku when using a third-party hosted addon), simply provide nil for the servers:
Or simply write configuration according to a Heroku document.
config.cache_store = :dalli_store,
(ENV["MEMCACHIER_SERVERS"] || "").split(","),
{
:username => ENV["MEMCACHIER_USERNAME"],
:password => ENV["MEMCACHIER_PASSWORD"],
:failover => true,
:socket_timeout => 1.5,
:socket_failure_delay => 0.2,
:down_retry_delay => 60,
:expires_in => 7.day,
:compress => true,
:namespace => 'Planna-prod',
and, in config/application.rb
is a middleware configuration as
config.middleware.use ActionDispatch::Session::MemCacheStore, expires_after: 7.day
and, config/initializers/session_store.rb
is
Rails.application.config.session_store :mem_cache_store
environmental variables
Enviromental variables are set as below,
- MEMCACHE_PASSWORD
- MEMCACHE_USERNAME
- MEMCACHE_SERVERS
- MEMCACHIER_PASSWORD
- MEMCACHIER_USERNAME
- MEMCACHIER_SERVERS
the first try
Modify config/initializers/session_store.rb
from
Rails.application.config.session_store :mem_cache_store
To
Rails.application.config.session_store :dalli_store
the second try
Modify config/application.rb
from
config.middleware.use ActionDispatch::Session::MemCacheStore, expires_after: 7.day
To
require 'action_dispatch/middleware/session/dalli_store'
config.middleware.use ActionDispatch::Session::DalliStore, expires_after: 7.day
and then I encountered the same problem as mentioned in this issue: https://github.com/petergoldstein/dalli/issues/613
so I tried to fix up the code the instruction In the issue 613.
Update the value of config.cache_store in your environment configuration to be :dalli_store
Set the config.session_store values to ActionDispatch::Session::CacheStore with whatever options you'd like
Then the problem in heroku (the output is below)
2017-04-25T10:00:38.564394+00:00 heroku[web.1]: Process exited with status 0
2017-04-25T10:00:39.945440+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 29870 -e production`
2017-04-25T10:00:42.430045+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:51: warning: constant ::Fixnum is deprecated
2017-04-25T10:00:42.430073+00:00 app[web.1]: /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.0.1/lib/active_support/xml_mini.rb:52: warning: constant ::Bignum is deprecated
2017-04-25T10:00:43.478293+00:00 app[web.1]: => Booting Puma
2017-04-25T10:00:43.478322+00:00 app[web.1]: => Rails 5.0.1 application starting in production on http://0.0.0.0:29870
2017-04-25T10:00:43.478323+00:00 app[web.1]: => Run `rails server -h` for more startup options