WEBrick has an unsafe shutdown process it tries to concurrently write and close the @shutdown_pipe
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- ruby
- 領域
- backend, networking
調査の方向性
まず lib/webrick/server.rb のシャットダウンパスをたどります。特に、クローズ、書き込み、シャットダウンハックに関する参照先の行を確認してください。ruby/spec の library/net/http/http/fixtures/http_server.rb と動作を比較し、サブスレッドが終了した後にのみ1つのスレッドが @shutdown_pipe をクローズし、並行した書き込みやクローズがないことを確認してください。
索引モデルが issue の本文から書いたものです。
説明
When WEBrick shutdowns, it tries to concurrently write and close a file descriptor, and even tries to close it from multiple threads:
closing it from the main webrick thread:
https://github.com/ruby/webrick/blob/841b7dadd5d2dc7cd5f5cceca2258ad53023f8dd/lib/webrick/server.rb#L207
closing it from an arbitrary thread:
https://github.com/ruby/webrick/blob/841b7dadd5d2dc7cd5f5cceca2258ad53023f8dd/lib/webrick/server.rb#L237
writing to it (from an arbitrary thread):
https://github.com/ruby/webrick/blob/841b7dadd5d2dc7cd5f5cceca2258ad53023f8dd/lib/webrick/server.rb#L227
The problem is if the write_nonblock which calls write(2) ends up happening once the fd is close(2)d then it's EBADF, or worse writing to the wrong file descriptor.
This became such an issue that ruby/spec stopped using WEBrick and rewrote to make its own HTTP server to avoid this issue. Also the commit message of https://github.com/ruby/spec/commit/d8ead5da7158d31660b87f2c9db7d80755a57b27 may be interesting.
Only one thread (e.g. the main webrick thread) should close it, and it should wait all sub-threads before closing it so there are concurrent writes to the close.
CRuby has some very complex logic in IO#close which avoids the issue in most cases but it's not clear if it's fully reliable: https://ruby.slack.com/archives/C02A3SL0S/p1636604027275700?thread_ts=1636592668.266300&cid=C02A3SL0S
IIRC I've seen it fail for ruby/spec too on CRuby.
cc @ioquatix
- 主要言語
- Ruby
- スター
- 327
- フォーク
- 113
- 平均マージ
- 4時間 2分
- マージ済み PR(30日)
- 1
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/webrick のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
ai-generated
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
hanami/hanami-cli#449 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
hanami/hanami-router#310 ·