Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 1.9.3:protocol.rb:160:[BUG]可能的缓冲区溢出:0为17_Ruby_Multithreading - Fatal编程技术网

Ruby 1.9.3:protocol.rb:160:[BUG]可能的缓冲区溢出:0为17

Ruby 1.9.3:protocol.rb:160:[BUG]可能的缓冲区溢出:0为17,ruby,multithreading,Ruby,Multithreading,我有一个Ruby脚本,它在1.8.7中工作得很好,但是现在在1.9.3中由于Ruby错误而崩溃 它使用一个简单的线程池来打开URL列表,以便对它们进行预缓存 以下是脚本的相关部分 线程池: require 'thread' # see http://burgestrand.se/articles/quick-and-simple-ruby-thread-pool.html class Pool def initialize(size) @size = size @jobs

我有一个Ruby脚本,它在1.8.7中工作得很好,但是现在在1.9.3中由于Ruby错误而崩溃

它使用一个简单的线程池来打开URL列表,以便对它们进行预缓存

以下是脚本的相关部分

线程池:

require 'thread'

# see http://burgestrand.se/articles/quick-and-simple-ruby-thread-pool.html
class Pool
  def initialize(size)
    @size = size
    @jobs = Queue.new

    @pool = Array.new(@size) do |i|
      Thread.new do
        Thread.current[:id] = i

        catch(:exit) do
          loop do
            job, args = @jobs.pop
            job.call(*args)
          end
        end
      end
    end
  end

  def schedule(*args, &block)
    @jobs << [block, args]
  end

  def shutdown
    @size.times do
      schedule { throw :exit }
    end

    @pool.map(&:join)
  end
end
下载代码:

pool = Pool.new(5)

# the_trips are loaded from the db
the_trips.each do |trip|
  cleaned_urls = TripPage.empty_cache(trip)

  cleaned_urls.each do |cleaned_url|
    pool.schedule do
      puts "Loading #{cleaned_url}..."
      begin
        load_url(cleaned_url)
        puts "#{cleaned_url} OK\n"
      rescue Timeout::Error => e
        puts "Caught Timeout error for #{cleaned_url} :("
      end
    end
  end
end

# wait for all threads to finish
puts "Done, shutting down the threadpool..."
pool.shutdown
设置到此为止

当我用Ruby 1.9.3运行这个程序时,我得到了以下结果:

Loading http://some.server.com/reisen/2010003...
Loading http://some.server.com/reisen/2010003-the-title...
Loading http://some.server.com/reisen/2010011...
Loading http://some.server.com/reisen/2010011-different-title...
Loading http://some.server.com/reisen/2010100...
http://some.server.com/reisen/2010003 OK
Loading http://some.server.com/reisen/2010100-yet-another-title...
~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:160: [BUG] probable buffer overflow: 17 for 0
ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-solaris2.10]

-- Control frame information -----------------------------------------------
c:0025 p:0017 s:0112 b:0112 l:000111 d:000111 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:160
c:0024 p:0061 s:0107 b:0107 l:000106 d:000106 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:124
c:0023 p:0159 s:0101 b:0101 l:000100 d:000100 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2584
c:0022 p:0024 s:0091 b:0091 l:000090 d:000090 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2669
c:0021 p:0106 s:0086 b:0086 l:000077 d:000085 BLOCK  ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1321
c:0020 p:---- s:0084 b:0084 l:000083 d:000083 FINISH
c:0019 p:---- s:0082 b:0082 l:000081 d:000081 CFUNC  :catch
c:0018 p:0025 s:0078 b:0078 l:000077 d:000077 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316
c:0017 p:0097 s:0072 b:0072 l:000071 d:000071 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1293
c:0016 p:0053 s:0065 b:0065 l:001d94 d:000064 BLOCK  clear_diskcache.rb:60
c:0015 p:0057 s:0060 b:0060 l:000059 d:000059 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745
c:0014 p:0182 s:0057 b:0057 l:000056 d:000056 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:557
c:0013 p:0140 s:0044 b:0044 l:001d94 d:001d94 METHOD clear_diskcache.rb:57
c:0012 p:0034 s:0031 b:0031 l:0012e4 d:000030 BLOCK  clear_diskcache.rb:115
c:0011 p:---- s:0028 b:0028 l:000027 d:000027 FINISH
c:0010 p:---- s:0026 b:0026 l:000025 d:000025 CFUNC  :call
c:0009 p:0034 s:0023 b:0023 l:002110 d:000022 BLOCK  clear_diskcache.rb:16
c:0008 p:---- s:0019 b:0019 l:000018 d:000018 FINISH
c:0007 p:---- s:0017 b:0017 l:000016 d:000016 CFUNC  :loop
c:0006 p:0009 s:0014 b:0014 l:002110 d:000013 BLOCK  clear_diskcache.rb:14
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :catch
c:0003 p:0038 s:0006 b:0006 l:002110 d:000005 BLOCK  clear_diskcache.rb:13
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP   

-- Ruby level backtrace information ----------------------------------------
clear_diskcache.rb:13:in `block (2 levels) in initialize'
clear_diskcache.rb:13http://some.server.com/reisen/2010011 OK
:in `catch'
clear_diskcache.rb:14:in `block (3 levels) in initialize'
clear_diskcache.rbLoading http://some.server.com/reisen/201T004...
:14:in `loop'
clear_diskcache.rb:16:in `block (4 levels) in initialize'
clear_diskcache.rb:16:in `call'
clear_diskcache.rb:113:in `block (4 levels) in <top (required)>'
clear_diskcache.rb:113:in `puts'
clear_diskcache.rb:113:in `puts'
clear_diskcache.rb:113:in `write'
加载http://some.server.com/reisen/2010003...
加载http://some.server.com/reisen/2010003-the-title...
加载http://some.server.com/reisen/2010011...
加载http://some.server.com/reisen/2010011-different-title...
加载http://some.server.com/reisen/2010100...
http://some.server.com/reisen/2010003 好啊
加载http://some.server.com/reisen/2010100-yet-another-title...
~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:160:[BUG]可能的缓冲区溢出:0为17
ruby 1.9.3p0(2011-10-30修订版33570)[i386-solaris2.10]
--控制帧信息-----------------------------------------------
c:0025 p:0017 s:0112 b:0112 l:000111 d:000111方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:160
c:0024P:0061S:0107B:0107L:000106D:000106方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:124
c:0023 p:0159 s:0101 b:0101 l:000100D:000100方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2584
c:0022p:0024s:0091b:0091l:000090d:000090方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2669
c:0021p:0106s:0086b:0086l:000077d:000085 BLOCK~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1321
c:0020 p:----s:0084 b:0084 l:000083 d:000083饰面
c:0019 p:----s:0082 b:0082 l:000081 d:000081 CFUNC:捕获
c:0018P:0025S:0078B:0078L:000077D:000077方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316
c:0017p:0097s:0072b:0072l:000071d:000071方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1293
c:0016 p:0053 s:0065 b:0065 l:001d94 d:000064块清除磁盘缓存。rb:60
c:0015P:0057S:0060B:0060L:000059D:000059方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745
c:0014 p:0182 s:0057 b:0057 l:000056 d:000056方法~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:557
c:0013 p:0140 s:0044 b:0044 l:001d94 d:001d94方法清除磁盘缓存。rb:57
c:0012 p:0034 s:0031 b:0031 l:0012e4 d:000030块清除磁盘缓存。rb:115
c:0011P:----s:0028B:0028L:000027D:000027面漆
c:0010P:----s:0026B:0026L:000025D:000025 CFUNC:呼叫
c:0009 p:0034 s:0023 b:0023 l:002110 d:000022块清除磁盘缓存。rb:16
c:0008P:----s:0019B:0019L:000018D:000018饰面
c:0007 p:----s:0017 b:0017 l:000016 d:000016 CFUNC:loop
c:0006 p:0009 s:0014 b:0014 l:002110 d:000013块清除磁盘缓存。rb:14
c:0005 p:----s:0012 b:0012 l:000011 d:000011饰面
c:0004 p:----s:0010 b:0010 l:000009 d:000009 CFUNC:捕获
c:0003 p:0038 s:0006 b:0006 l:002110 d:000005块清除磁盘缓存。rb:13
c:0002 p:----s:0004 b:0004 l:000003 d:000003饰面
c:0001 p:----s:0002 b:0002 l:000001 d:000001顶部
--Ruby级别回溯信息----------------------------------------
清除\u diskcache.rb:13:in`block(2个级别)in initialize'
清除磁盘缓存。rb:13http://some.server.com/reisen/2010011 好啊
:在“catch”中
清除\u diskcache.rb:14:在“初始化中的块(3级)”中
清除\u diskcache.rbLoadinghttp://some.server.com/reisen/201T004...
:14:在“循环”中
清除\u diskcache.rb:16:in`block(4个级别)in initialize'
清除磁盘缓存。rb:16:in'call'
清除\u diskcache.rb:113:in'block(4层)in'
清除磁盘缓存。rb:113:in'puts'
清除磁盘缓存。rb:113:in'puts'
清除磁盘缓存。rb:113:in'write'
知道有什么问题吗? 我发现了这个,但我不能100%确定这是否是我看到的bug:

如果是的话,看起来修复程序要到Ruby 2.0才能发布

Loading http://some.server.com/reisen/2010003...
Loading http://some.server.com/reisen/2010003-the-title...
Loading http://some.server.com/reisen/2010011...
Loading http://some.server.com/reisen/2010011-different-title...
Loading http://some.server.com/reisen/2010100...
http://some.server.com/reisen/2010003 OK
Loading http://some.server.com/reisen/2010100-yet-another-title...
~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:160: [BUG] probable buffer overflow: 17 for 0
ruby 1.9.3p0 (2011-10-30 revision 33570) [i386-solaris2.10]

-- Control frame information -----------------------------------------------
c:0025 p:0017 s:0112 b:0112 l:000111 d:000111 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:160
c:0024 p:0061 s:0107 b:0107 l:000106 d:000106 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/protocol.rb:124
c:0023 p:0159 s:0101 b:0101 l:000100 d:000100 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2584
c:0022 p:0024 s:0091 b:0091 l:000090 d:000090 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:2669
c:0021 p:0106 s:0086 b:0086 l:000077 d:000085 BLOCK  ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1321
c:0020 p:---- s:0084 b:0084 l:000083 d:000083 FINISH
c:0019 p:---- s:0082 b:0082 l:000081 d:000081 CFUNC  :catch
c:0018 p:0025 s:0078 b:0078 l:000077 d:000077 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1316
c:0017 p:0097 s:0072 b:0072 l:000071 d:000071 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:1293
c:0016 p:0053 s:0065 b:0065 l:001d94 d:000064 BLOCK  clear_diskcache.rb:60
c:0015 p:0057 s:0060 b:0060 l:000059 d:000059 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:745
c:0014 p:0182 s:0057 b:0057 l:000056 d:000056 METHOD ~/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/net/http.rb:557
c:0013 p:0140 s:0044 b:0044 l:001d94 d:001d94 METHOD clear_diskcache.rb:57
c:0012 p:0034 s:0031 b:0031 l:0012e4 d:000030 BLOCK  clear_diskcache.rb:115
c:0011 p:---- s:0028 b:0028 l:000027 d:000027 FINISH
c:0010 p:---- s:0026 b:0026 l:000025 d:000025 CFUNC  :call
c:0009 p:0034 s:0023 b:0023 l:002110 d:000022 BLOCK  clear_diskcache.rb:16
c:0008 p:---- s:0019 b:0019 l:000018 d:000018 FINISH
c:0007 p:---- s:0017 b:0017 l:000016 d:000016 CFUNC  :loop
c:0006 p:0009 s:0014 b:0014 l:002110 d:000013 BLOCK  clear_diskcache.rb:14
c:0005 p:---- s:0012 b:0012 l:000011 d:000011 FINISH
c:0004 p:---- s:0010 b:0010 l:000009 d:000009 CFUNC  :catch
c:0003 p:0038 s:0006 b:0006 l:002110 d:000005 BLOCK  clear_diskcache.rb:13
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:---- s:0002 b:0002 l:000001 d:000001 TOP   

-- Ruby level backtrace information ----------------------------------------
clear_diskcache.rb:13:in `block (2 levels) in initialize'
clear_diskcache.rb:13http://some.server.com/reisen/2010011 OK
:in `catch'
clear_diskcache.rb:14:in `block (3 levels) in initialize'
clear_diskcache.rbLoading http://some.server.com/reisen/201T004...
:14:in `loop'
clear_diskcache.rb:16:in `block (4 levels) in initialize'
clear_diskcache.rb:16:in `call'
clear_diskcache.rb:113:in `block (4 levels) in <top (required)>'
clear_diskcache.rb:113:in `puts'
clear_diskcache.rb:113:in `puts'
clear_diskcache.rb:113:in `write'