Issue #6230 has been reported by nobuoka (yu nobuoka).

----------------------------------------
Bug #6230: [WEBrick] WEBrick::HTTPResponse#body ??? IO ??????吾?с?????茯??粋昭??帥?? read ??<?純????????篏帥?c????????????綽?荀?篁ヤ????????????????????
https://bugs.ruby-lang.org/issues/6230

Author: nobuoka (yu nobuoka)
Status: Open
Priority: Normal
Assignee: 
Category: 
Target version: 
ruby -v: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]


WEBrick::HTTPResponse ??? @body ???? IO ??????吾?с??????荐????с????障????????@body ??荐絎?????????? IO ??????吾?с???????????茯??水?冴????????? IO#read( @buffer_size ) ??ц???????????????????@buffer_size ?????????絨?????????若?帥??絎??????????????????????翫????????綽?荀?篁ヤ???????????????????????障????障????? IO#read ??<?純???????篁???????? IO#readpartial ??<?純????????篏睡??????????????????????????с???????????с??????????????

patch ???羞私???????障?????

 diff --git a/lib/webrick/httpresponse.rb b/lib/webrick/httpresponse.rb
 index 0d36c07..4942588 100644
 --- a/lib/webrick/httpresponse.rb
 +++ b/lib/webrick/httpresponse.rb
 @@ -330,13 +330,17 @@ module WEBrick
 if @request_method == "HEAD"
 # do nothing
 elsif chunked?
 -          while buf = @body.read(@buffer_size)
 -            next if buf.empty?
 -            data = ""
 -            data << format("%x", buf.bytesize) << CRLF
 -            data << buf << CRLF
 -            _write_data(socket, data)
 -            @sent_size += buf.bytesize
 +          begin
 +            while true
 +              buf = @body.readpartial( @buffer_size )
 +              next if buf.empty?
 +              data = ""
 +              data << format("%x", buf.bytesize) << CRLF
 +              data << buf << CRLF
 +              _write_data(socket, data)
 +              @sent_size += buf.bytesize
 +            end
 +          resuce EOFError # do nothing
            end
            _write_data(socket, "0#{CRLF}#{CRLF}")
          else

??隙????????違????倶??????箴??????遺札筝??????????? Server-Sent Events ??у??膈?????????泣?若????若??絎????????????????翫????с?????

 require 'webrick'
 
 server = WEBrick::HTTPServer.new( Port: 8000 )
 server.mount_proc( '/time_stream' ) do |req, res|
   res.content_type = 'text/event-stream'
   r,w = IO.pipe
  res.body = r
    res.chunked = true
   t = Thread.new do
     10.times do
       Thread.pass
       w << 'data: ' << Time.now.to_s << "\x0D\x0A"
       w << "\x0D\x0A"
       sleep 1
     end
     w.close()
   end
 end
 
 trap :INT do server.shutdown end
 server.start


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