Ruby sinatra + puma 出现的问题求解

towonzhou · 2013年11月14日 · 最后由 dddd1919 回复于 2013年11月23日 · 2563 次阅读

框架是 sinatra, 用的 puma 起的. 跑一段时间后会出现请求混乱的问题, controller 逻辑如下

def debug name, data
  puts "-----#{name}"
  puts data
end

def hello(params = {})
  debug "----params", params
  ......
  puts "----someting"
end

多次请求 http://localhost/controllers/hello?a=111&b=222 输出为

-----params
-----params
-----params
-----params
-----params
-----params
-----someting
{"a"=> "111", "b"=>"222"}
{"a"=> "111", "b"=>"222"}
{"a"=> "111", "b"=>"222"}
{"a"=> "111", "b"=>"222"}
{"a"=> "111", "b"=>"222"}
{"a"=> "111", "b"=>"222"}

其中"....."部分有数据库读写操作和 http 请求操作 之后报错

message type 0x54 arrived from server while idle
message type 0x44 arrived from server while idle
message type 0x43 arrived from server while idle
message type 0x5a arrived from server while idle
ActiveRecord::StatementInvalid - PG::UnableToSend: :             SELECT a.attname, format_type(a.atttypid, a.atttypmod),
                     pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
              FROM pg_attribute a LEFT JOIN pg_attrdef d
                ON a.attrelid = d.adrelid AND a.attnum = d.adnum
             WHERE a.attrelid = '"mobiles"'::regclass
               AND a.attnum > 0 AND NOT a.attisdropped
             ORDER BY a.attnum
:

在 model 进行 save 的时候卡住不动了。

C--C 后报错

^C- Gracefully stopping, waiting for requests to finish
^CThreadError - Attempt to unlock a mutex which is locked by another thread:

求解原因.....

activerecord 和 pg 的版本?

#1 楼 @luikore pg 的版本是 9.1 activerecord-postgis-adapter 是 0.6.5 activerecord 是 3.2.14 puma 2.6.0 用 rainbows 4.5.0 启动是正常的

几个进程?能贴点操作代码看看不?怎么感觉是程序的问题喽

#3 楼 @dddd1919 代码很简单 people = People.where(id: @id).first zhou = people.zhou 然后改变 people 和 zhou 中的各属性值之后,save,就没了

直接控制台下 puam 起的 就一个进程

ActiveRecord::StatementInvalid - PG::UnableToSend: 可能是中间件或 pg 的问题吧,去 git 看下有没有 issue

需要 登录 后方可回复, 如果你还没有账号请 注册新账号