仅当工作进程 puma> 1 时,我才会丢失与 Ruby + Sinatra + puma + sequel 的用户会话

问题描述

我在 Heroku 中使用 Ruby + Sinatra + puma + sequel 的应用程序正常,而当增加工作进程 = 2 时工作进程 = 1 或者如果增加 dyno = 2 我开始遇到在系统的不同点随机丢失用户会话的问题导致很难通过 heroku 日志定位特定错误。

同一个应用程序适用于:

但是你失去了 session[:user] 的值:

我的应用机架 sinatra 类:

class Main <Sinatra :: Aplicación
    use Rack :: Session :: Pool
    set: protection,: except =>: frame_options

    def usuarioLogueado?          
      if defined?( session[:usuario] )   
        if session[:usuario].nil?
          return false
        else
          return true
        end
      else
        return false
      end    
    end

    get "/" do  
       if usuarioLogueado?  
               redirect "/app"
               .....
       else
              redirect "/home"
       end
    end
end

我的续集关系:

pool_size  = 10
@ db = Sequel.connect (strConexion,: max_connections => pool_size )
@ db.extension (: connection_validator)
@ db.pool.connection_validation_timeout = -1

我的 puma.rb:(最多 20 个连接数据库)

workers Integer (ENV ['WEB_CONCURRENCY'] || 1)
threads_count = Integer (ENV ['MAX_THREADS'] || 10)
threads threads_count,threads_count

preload_app!

rackup DefaultRackup
port ENV ['PORT'] || 3000

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)