Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#102 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
ruby

Direzione di ricerca

Inizia tracciando il percorso di shutdown in lib/webrick/server.rb, soprattutto le righe indicate relative alla chiusura, alla scrittura e all’hack di shutdown. Confronta il comportamento con ruby/spec's library/net/http/http/fixtures/http_server.rb e verifica che un thread chiuda @shutdown_pipe solo dopo che i sottothread hanno terminato, senza scritture o chiusure concorrenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
Ruby
Stelle
327
Fork
113
Merge medio
4h 2m
PR unite (30g)
1

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ruby/webrick

Tutte le issue di ruby/webrick

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.