Actioncable超时断开未触发

时间:2016-09-15 10:49:53

标签: ruby-on-rails nginx puma actioncable

在Actioncable上,当我禁用wifi来模拟互联网丢失时,Channel中的unsubscribed方法或Connection中的disconnect方法未触发。如何激活超时断开连接?

这是我使用rails / capistrano / puma / nginx的actioncable配置:

Rails 5.0.0.1方:

# config/cable.yml
staging:
    adapter: redis
    url: redis://localhost:6379/1

# cable/config.ru
require ::File.expand_path('../../config/environment', __FILE__)
Rails.application.eager_load!

run ActionCable.server

和capistrano / puma

set :puma_rackup, -> { File.join(current_path, 'cable/config.ru') }

Nginx方面:

upstream app {
  server unix:/home/ubuntu/rails-app/shared/tmp/sockets/puma.sock fail_timeout=0;
}

server {
  listen 443 ssl;
  server_name ws.domain.co;

  ssl on;
  ssl_certificate /etc/letsencrypt/live/domain.co/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/domain.co/privkey.pem;

  ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';

  location / {
    proxy_pass http://app;
    proxy_http_version 1.1;
    proxy_set_header Upgrade websocket;
    proxy_set_header Connection Upgrade;
  }

}

1 个答案:

答案 0 :(得分:2)

我也遇到过这个问题,似乎断开连接确实会触发。根据文档,只需几秒钟就可以了,但几分钟后。

您可以'watch -n 1 'netstat -na | grep YourPort'看到该连接实际上仍然存在,因此不应触发断开连接回调。

我在github上就此问题打开了一个问题。 https://github.com/rails/rails/issues/27082