Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#102 4 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
38/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ruby
Lĩnh vực
backend, networking

Hướng nghiên cứu

Bắt đầu bằng cách lần theo luồng shutdown trong lib/webrick/server.rb, đặc biệt là các dòng được tham chiếu liên quan đến việc đóng, ghi và shutdown hack. So sánh hành vi với ruby/spec's library/net/http/http/fixtures/http_server.rb và xác minh rằng một thread chỉ đóng @shutdown_pipe sau khi các sub-thread hoàn tất, không có thao tác ghi hoặc đóng đồng thời.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Ruby
Star
327
Fork
113
Merge trung bình
4 giờ 2 phút
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của ruby/webrick

Tất cả issue của ruby/webrick

Issue tương tự

Thêm issue về Ruby

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.