ruby / webrick

HTTP server toolkit
BSD 2-Clause "Simplified" License
286 stars 97 forks source link

Catch CONNRESET on `eof?` #86

Open carlhoerberg opened 2 years ago

carlhoerberg commented 2 years ago

Some clients (wget) resets the TCP connection when 404 is received, webrick then logs:

::1 - - [18/Jan/2022:12:41:41 CET] "GET /404 HTTP/1.1" 404 7173
- -> /404
[2022-01-18 12:41:41] ERROR Errno::ECONNRESET: Connection reset by peer @ io_fillbuf - fd:9
        /home/carl/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/httpserver.rb:82:in `eof?'
        /home/carl/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/httpserver.rb:82:in `run'
        /home/carl/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/webrick-1.7.0/lib/webrick/server.rb:310:in `block in start_thread'

Screenshot from 2022-01-18 12-43-23

olleolleolle commented 2 years ago

@carlhoerberg Is there a chance of adding a test for this? https://github.com/ruby/webrick/blob/master/test/webrick/test_cgi.rb - perhaps there?

tisba commented 3 weeks ago

I don't see how this change can have any impact on the backtrace from the PR description. The PR changes WEBrick::CGI::Socket#eof? but the trace indicates that WEBrick::HTTPServer is used and causing the error.

Also: I also cannot reproduce this behavior with wget.

However, I also see this error from time to time, I think when using Safari, but not 100% sure when this happens exactly. In any case WEBrick::HTTPServer#run does have an issue when the connection is reset. Testing this is a little tricky and there are multiple ways to address this. Will send a PR when I have poked around a little more.