在 Heroku 上使用 ActionCable 部署 Rails5 beta3 应用程序时 Redis 密码无效

Posted

技术标签:

【中文标题】在 Heroku 上使用 ActionCable 部署 Rails5 beta3 应用程序时 Redis 密码无效【英文标题】:Invalid Redis password while deploying Rails5 beta3 app with ActionCable on Heroku 【发布时间】:2016-04-23 23:36:07 【问题描述】:

首先,我的应用程序在开发中运行良好。 我一直在按照教程在 Heroku 上部署 Action Cable 应用程序,但遇到了这个问题:

我的应用程序的配置是这样的:

config/cable.yml:

development: &development
  :url: redis://localhost:6379
  :host: localhost
  :port: 6379
  :timeout: 1
  :inline: true
test: *development
production: &production
  :url: redis://redistogo:MYREDISTOGOPASSWORD@lab.redistogo.com:10108/
  :host: tarpon.redistogo.com
  :port: 10108
  :password: MYREDISTOGOPASSWORD
  :inline: true
  :timeout: 1

初始化器/redis.rb

uri = URI.parse(ENV['REDISTOGO_URL'] || 'redis://localhost:6379/' )
REDIS = Redis.new(host: uri.host, port: uri.port, password: uri.password)

config/routes.rb 中的这一行

mount ActionCable.server => '/cable'

在生产中的应用程序中,我没有 JS 控制台错误或警告,但在日志中,我可以看到为什么 ActionCable 魔法不起作用,而且当 websocket 尝试时,我的 redistogo 密码似乎是错误的访问它? 我可以heroku run console,然后尝试REDIS.set()/get(),效果很好。

在日志中,我有这个错误:

2016-04-23T23:26:36.308976+00:00 app[web.1]: [3] - Worker 0 (pid: 1078) booted, phase: 0
2016-04-23T23:26:36.316316+00:00 heroku[router]: at=info method=GET path="/cable" host=myapp.herokuapp.com request_id=7752b409-3d26-4a82-9e39-73c34eb6819c fwd="90.109.65.65" dyno=web.1 connect=0ms service=170ms status=101 bytes=129
2016-04-23T23:26:37.090881+00:00 app[web.1]: Started GET "/cable" for 90.109.65.65 at 2016-04-23 23:26:37 +0000
2016-04-23T23:26:37.139914+00:00 app[web.1]: Started GET "/cable" [WebSocket] for 90.109.65.65 at 2016-04-23 23:26:37 +0000
2016-04-23T23:26:37.139965+00:00 app[web.1]: Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: Upgrade, HTTP_UPGRADE: websocket)
2016-04-23T23:26:37.240234+00:00 app[web.1]: /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:121:in `call': ERR invalid password (Redis::CommandError)
2016-04-23T23:26:37.240241+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:102:in `block in connect'
2016-04-23T23:26:37.240242+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:293:in `with_reconnect'
2016-04-23T23:26:37.240243+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:100:in `connect'
2016-04-23T23:26:37.240244+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:276:in `with_socket_timeout'
2016-04-23T23:26:37.240246+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:133:in `call_loop'
2016-04-23T23:26:37.240246+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/subscribe.rb:43:in `subscription'
2016-04-23T23:26:37.240247+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/subscribe.rb:12:in `subscribe'
2016-04-23T23:26:37.240248+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:2760:in `_subscription'
2016-04-23T23:26:37.240248+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:2138:in `block in subscribe'
2016-04-23T23:26:37.240249+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:58:in `block in synchronize'
2016-04-23T23:26:37.240251+00:00 app[web.1]:    from /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
2016-04-23T23:26:37.240252+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:58:in `synchronize'
2016-04-23T23:26:37.240252+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:2137:in `subscribe'
2016-04-23T23:26:37.240253+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.0.beta3/lib/action_cable/subscription_adapter/redis.rb:70:in `block in listen'
2016-04-23T23:26:37.240254+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:293:in `with_reconnect'
2016-04-23T23:26:37.240254+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:64:in `block in with_reconnect'
2016-04-23T23:26:37.240255+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:58:in `block in synchronize'
2016-04-23T23:26:37.240256+00:00 app[web.1]:    from /app/vendor/ruby-2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
2016-04-23T23:26:37.240256+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:58:in `synchronize'
2016-04-23T23:26:37.240257+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:63:in `with_reconnect'
2016-04-23T23:26:37.240259+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.0.beta3/lib/action_cable/subscription_adapter/redis.rb:67:in `listen'
2016-04-23T23:26:37.240259+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis.rb:70:in `without_reconnect'
2016-04-23T23:26:37.240261+00:00 app[web.1]:    from /app/vendor/bundle/ruby/2.3.0/gems/actioncable-5.0.0.beta3/lib/action_cable/subscription_adapter/redis.rb:141:in `block in ensure_listener_running'

谢谢,

【问题讨论】:

【参考方案1】:

好吧,我只是在这个问题上浪费了很多时间。问题是我只是在过于密切地关注示例时弄乱了另一个 redistogo 子域......

config/cable.yml:

production: &production
  :url: redis://redistogo:MYREDISTOGOPASSWORD@lab.redistogo.com:10108/
  -------
  :host: tarpon.redistogo.com
  +++++++
  :host: lab.redistogo.com

【讨论】:

以上是关于在 Heroku 上使用 ActionCable 部署 Rails5 beta3 应用程序时 Redis 密码无效的主要内容,如果未能解决你的问题,请参考以下文章

在 Heroku 上部署 ActionCable (Rails 5 beta4)

Heroku 上的 ActionCable 服务器响应时间

动作电缆在本地订阅,但不在 heroku 上

部署到heroku后actioncable不起作用

Heroku Websocket到自定义域

子域而不是子目录上的 ActionCable