Net::HTTP、ZlibとFiberError

咳といいます。

Net::HTTP#requestをブロック付きで呼び出し、ブロックの中で
Net::HTTPResponse#read_bodyをブロック付きで呼び出しています。

例えばこんな雰囲気。

oauth.request(:GET, 'https://userstream.twitter.com/2/user.json') do 

|r|
r.read_body do |chunk|
json.push(chunk) # ←ここ
end
end

内側のブロックの中でFiberを切り替えると次のようなFiberError例外が発生します。

Exception FiberError' at drip_tw.rb:36 - fiber called across stack rewinding barrier ExceptionZlib::BufError’ at
/usr/local/lib/ruby/2.2.0/net/http/response.rb:357 - buffer error
Exception `Zlib::BufError’ at /usr/local/lib/ruby/2.2.0/net/http.rb:1442

  • buffer error
    /usr/local/lib/ruby/2.2.0/net/http/response.rb:357:in finish': buffer error (Zlib::BufError) from /usr/local/lib/ruby/2.2.0/net/http/response.rb:357:infinish’
    from /usr/local/lib/ruby/2.2.0/net/http/response.rb:262:in ensure in inflater' from /usr/local/lib/ruby/2.2.0/net/http/response.rb:262:ininflater’
    from /usr/local/lib/ruby/2.2.0/net/http/response.rb:274:in
    read_body_0' from /usr/local/lib/ruby/2.2.0/net/http/response.rb:201:inread_body’
    from drip_tw.rb:180:in block in drip_stream' from /usr/local/lib/ruby/2.2.0/net/http.rb:1415:inblock (2 levels)
    in transport_request’
    from /usr/local/lib/ruby/2.2.0/net/http/response.rb:162:in
    reading_body' from /usr/local/lib/ruby/2.2.0/net/http.rb:1414:inblock in
    transport_request’
    from /usr/local/lib/ruby/2.2.0/net/http.rb:1405:in catch' from /usr/local/lib/ruby/2.2.0/net/http.rb:1405:intransport_request’
    from /usr/local/lib/ruby/2.2.0/net/http.rb:1378:in request' from /usr/local/lib/ruby/2.2.0/net/http.rb:1371:inblock in request’
    from /usr/local/lib/ruby/2.2.0/net/http.rb:853:in start' from /usr/local/lib/ruby/2.2.0/net/http.rb:1369:inrequest’
    from drip_tw.rb:118:in request' from drip_tw.rb:179:indrip_stream’
    from drip_tw.rb:298:in `’

Rubyのバージョンはruby 2.2.0dev (2014-02-10 trunk 44902) [x86_64-darwin13.0]。
1.9系の頃は動いていたスクリプトです。
Fiberと同様な動作をするThread版を使うと例外は発生しません。

Zlibがrb_protect()しているときにFiberを切り替えているってことでしょうか?(勘)

再現させる最小のコードになってないし実行の準備がめんどくさいけど、件のコードはこちらです。

https://github.com/seki/Drip/blob/master/sample/drip_tw.rb
(178行目のDripFiberをDripThreadにするとThread版になります)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs