1

I'm reporting this because I haven't found any other reports of code that worked previously, but now generates random Ruby segmentation fault errors after upgrading to the just-released Ruby 2.0.0-p0.

I have a Sinatra application that generates a string that an .erb template embeds in a data- tag in the DOM. As I stated, this worked just fine until I upgraded to Ruby 2.0. With 2.0.0-p0, It gives segmentation fault errors, usually after about 5 to 20 runs of the program. When I revert to Ruby 1.9, it works perfectly again and I can run the program hundreds of times without problems.

Here's an example of the results I get from these errors. This is the first few lines of the 'control frame information' section of the error listing:

-- Control frame information -----------------------------------------------
c:0061 p:0028 s:0315 e:000303 METHOD terrain_001.rb:509
c:0060 p:0012 s:0298 e:000296 BLOCK  terrain_001.rb:494 [FINISH]
c:0059 p:---- s:0294 e:000293 CFUNC  :each
c:0058 p:0008 s:0291 e:000290 BLOCK  terrain_001.rb:493 [FINISH]
c:0057 p:---- s:0288 e:000287 CFUNC  :each
c:0056 p:0023 s:0285 e:000284 METHOD terrain_001.rb:492
c:0055 p:0068 s:0281 e:000279 BLOCK  /home/john/Desktop/stra-dams/views/index.erb:3 [FINISH]

The line numbers indicated as the location where the error occured are always in the following code, somewhere inside the definition for the hash values{} after the encode method has been called by the line str << encode(hex) in the terrain_string method:

def terrain_string
  str = ""
  @terrain = build_terrain
  @terrain.each do |t|
    t.each do |hex|
      str << encode(hex)
    end
  end
  str
end


# encode elevation values to a one-character code
def encode(elev)
  values = {
    :elev_10 => "a",
    :elev_20 => "b",
    :elev_30 => "c",
    :elev_40 => "d",
    :elev_50 => "e",
    :elev_60 => "f",
    :elev_70 => "g",
    :elev_80 => "h",

Maybe after other people have tried the brand new Ruby 2.0 release, others will report similar errors. In the meantime, is there anything else I should be looking at that might help pinpoint the problem with the 2.0.0-p0 release?

4

1 回答 1

2

使用我在 Ruby 2.0.0 上的新开源框架,我得到了非常相似的东西。Ruby 2.0.0-p0 似乎有问题导致这些段错误,或者与常见 gem 的一些兼容性问题。它的随机性使得很难确定哪个库负责(如果有的话)。

当我的网络应用程序在多线程或分叉模式下运行时,我似乎最容易得到错误,例如使用 Phusion Passenger 的智能生成方法。我只是希望它会在 ruby​​ 2.0.0 的下一个补丁级别中得到修复。

请注意,实际的段错误发生在执行过程中的不同点。有时在 Nokogiri 中,有时在 ERB、SASS 或 Tilt 中。基本上,这是一个时间问题。我的应用程序很小,因此花费最多的时间在 Nokogiri 中渲染模板和后处理响应,因此大部分时间段错误都发生在此处。

于 2013-03-19T05:53:42.273 回答