Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

WEBrick has an unsafe shutdown process it tries to concurrently write and close the @shutdown_pipe

オープン
#102 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
38/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
ruby

調査の方向性

まず 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

A hack:
https://github.com/ruby/webrick/blob/841b7dadd5d2dc7cd5f5cceca2258ad53023f8dd/lib/webrick/server.rb#L353

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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ruby/webrick のほかの issue

ruby/webrick の issue をすべて見る

似ている issue

Ruby の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。