Issue #11742 has been updated by Usaku NAKAMURA.


そんなアプリは死んでおけばいいんじゃないですかね^^

互換性をどこまで保つかって難しい判断なわけですが、うーん。
2.1についてはまた後で考えます(そして時間切れで自動的にWONTFIXになる)。

----------------------------------------
Bug #11742: lib/webrick/utils.rb:196:in `register': ERROR RuntimeError: can't add a new key into hash during iteration
https://bugs.ruby-lang.org/issues/11742#change-56883

* Author: Naohisa Goto
* Status: Closed
* Priority: Normal
* Assignee: Hiroshi Nakamura
* ruby -v: -
* Backport: 2.0.0: WONTFIX, 2.1: REQUIRED, 2.2: REQUIRED
----------------------------------------
RubyCI上にて、たまに以下のFailureが発生しています。

~~~
  1) Failure:
TestNetHTTP_v1_2_chunked#test_set_form [/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/test/net/http/test_http.rb:679]:
Expected /\A--(?<boundary>\S+)/ to match "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n<HTML>\n  <HEAD><TITLE>Internal Server Error</TITLE></HEAD>\n  <BODY>\n    <H1>Internal Server Error</H1>\n    can't add a new key into hash during iteration\n    <HR>\n    <ADDRESS>\n     WEBrick/1.3.1 (Ruby/2.3.0/2015-11-26) OpenSSL/1.0.1p at\n     127.0.0.1:46098\n    </ADDRESS>\n  </BODY>\n</HTML>\n".

  2) Failure:
TestNetHTTP_v1_2_chunked#test_set_form [/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/test/net/http/utils.rb:46]:
<[]> expected but was
<["[2015-11-26 03:54:25] ERROR RuntimeError: can't add a new key into hash during iteration\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/utils.rb:196:in `register'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/utils.rb:139:in `block in register'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/utils.rb:138:in `synchronize'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/utils.rb:138:in `register'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/utils.rb:227:in `timeout'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httprequest.rb:519:in `_read_data'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httprequest.rb:530:in `read_line'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httprequest.rb:491:in `read_chunk_size'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httprequest.rb:510:in `read_chunked'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httprequest.rb:470:in `read_body'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httprequest.rb:255:in `body'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/test/net/http/utils.rb:91:in `do_POST'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httpservlet/abstract.rb:106:in `service'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httpserver.rb:139:in `service'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/httpserver.rb:95:in `run'\n\t/home/rubyci/unstable11s/tmp/build/20151126T012513Z/ruby/lib/webrick/server.rb:295:in `block in start_thread'\n"]>.
~~~

上記は Solaris 11 sparc ですが、他のOS・アーキテクチャでも発生しているときがあるようです。

@timeout_info へのアクセスの排他制御が考慮されていないように見えます。
initializeメソッド内で起動されるスレッド `@watcher` 内で `@timeout_info.each {|thread, ary|` を回しているのと、registerメソッド内冒頭で `@timeout_info[thread] ||= Array.new` しているのが、同時に発生したときにエラーが出る?



-- 
https://bugs.ruby-lang.org/