小编Jac*_*ins的帖子

ActionCable超时 - Heroku上的"空闲连接"

我们已经在Heroku上使用ActionCable已经有一段时间了,总体而言它运行良好.但是,我们H15 Idle Connection每天都会多次看到错误.他们总是有path=/cable很长一段service时间,所以这种联系在一段时间内绝对是健康和健康的.

Dec 2016 08:32:22.057 heroku router - - at=error code=H15 desc="Idle connection" 
method=GET path="/cable" host=<our host> dyno=web.2 connect=1ms service=928755ms status=503
Run Code Online (Sandbox Code Playgroud)

我相信我们的设置非常标准,并且紧跟ActionCable的Rails文档:

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
    end

    protected

    def find_verified_user
      if current_user = User.find_by(id: cookies.signed[:user_id])
        current_user
      else
        # reject_unauthorized_connection
      end
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

我们有三个这样简单的渠道:

class ActivitiesChannel < ApplicationCable::Channel  

  def subscribed
    stream_from "activities_#{current_user.id}" if current_user
  end
end
Run Code Online (Sandbox Code Playgroud)

编辑添加 - Javascript代码:

app/assets/javascripts/channels/setup.js:

//= require cable …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails heroku ruby-on-rails-5 actioncable

12
推荐指数
1
解决办法
779
查看次数

devise_token_auth&Rails 5 - IndexError:字符串不匹配

我正在尝试使用devise_token_auth版本登录现有用户0.1.38,但我正在使用IndexError: string not matched该库sessions_controller.

IndexError (string not matched):

devise_token_auth (0.1.38) app/controllers/devise_token_auth/sessions_controller.rb:37:in `[]='
devise_token_auth (0.1.38) app/controllers/devise_token_auth/sessions_controller.rb:37:in `create'
actionpack (5.0.0) lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
actionpack (5.0.0) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.0) lib/action_controller/metal/rendering.rb:30:in `process_action'
actionpack (5.0.0) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
Run Code Online (Sandbox Code Playgroud)

相关代码sessions_controller是:

  if @resource and valid_params?(field, q_value) and @resource.valid_password?(resource_params[:password]) and (!@resource.respond_to?(:active_for_authentication?) or @resource.active_for_authentication?)
    # create client id
    @client_id = SecureRandom.urlsafe_base64(nil, false)
    @token     = SecureRandom.urlsafe_base64(nil, false)

    #  !! Next line is line 37 with the error !!
    @resource.tokens[@client_id] …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise http-token-authentication ruby-on-rails-5

6
推荐指数
1
解决办法
1237
查看次数

Ruby/Rails 字符串内存泄漏 - 数据库字符串是最严重的罪犯?

一段时间以来,我一直在与 Rails 应用程序中的内存泄漏问题作斗争。我我已经将部分问题跟踪到了某个班级,但我看到了令人困惑的结果memory-profiler

简短的背景 - 该类AuditMessage根据审核日志记录(来自 gem)中的数据构造用户友好的字符串audited。此消息是在创建审核记录时构建的,因此会经常运行。我的第一个测试是对内存进行基准测试,以确认审核和消息生成是问题所在:

Full audit with AuditMessage:   91 M memsize, 8.7 M retained
Without AuditMessage:           59 M memsize, 4.5 M retained
Without auditing at all:        33.8 M memsize; 2.9 M retained
Run Code Online (Sandbox Code Playgroud)

这告诉我审计和AuditMessage有问题。我根据这篇调试文章创建了一个简短的测试文件。本质上,我生成 100 条消息,运行垃圾收集,检查内存,然后重复。

ENV['RAILS_ENV'] = 'production'
require 'objspace'
require 'memory_profiler'
require File.expand_path("../config/environment", __FILE__)

def rss
  `ps -eo pid,rss | grep #{Process.pid} | awk '{print $2}'`.to_i
end

AuditMessage.new(AuditEntry.first).text_message

GC.start
puts "rss: #{rss} …
Run Code Online (Sandbox Code Playgroud)

ruby activerecord garbage-collection memory-leaks ruby-on-rails

6
推荐指数
0
解决办法
608
查看次数

多个 Solr 实例 - 第二个 Solr 在启动时锁定

我一直试图找出一个工作流程,即使开发实例正在运行,我的 Minitest 套件也会启动第二个 Solr 实例进行功能测试。但是,我在启动服务器时遇到了问题(即当我在测试之外启动它们时)。

要启动我正在使用的服务器:

RAILS_ENV=development bin/rake sunspot:solr:start
RAILS_ENV=test bin/rake sunspot:solr:start
Run Code Online (Sandbox Code Playgroud)

但是,无论哪个服务器第二次启动都会被锁定。任何在测试中或仅在开发中访问服务器的尝试都会产生此错误:

RSolr::Error::Http - 500 Internal Server Error
Error:     {msg=SolrCore 'test& 'is not available due to init failure: Index locked for write for core 'test'. Solr now longer supports forceful unlocking via 'unlockOnStartup'. Please verify locks manually!,trace=org.apache.solr.common.SolrException: SolrCore 'test' is not available due to init failure: Index locked for write for core 'test'. Solr now longer supports forceful unlocking via 'unlockOnStartup'. Please verify locks manually!
    at org.apache.solr.core.CoreContainer.getCore(CoreContainer.java:974) …
Run Code Online (Sandbox Code Playgroud)

solr ruby-on-rails sunspot sunspot-rails

5
推荐指数
0
解决办法
274
查看次数