File tree Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Expand file tree Collapse file tree 3 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -349,7 +349,7 @@ def read(length)
349349
350350 # Read a line from the connection.
351351 #
352- # @returns [String | Nil] the line read, or nil if the connection is gracefully closed.
352+ # @returns [String | Nil] the line read, or nil if the connection is closed.
353353 # @raises [LineLengthError] if the line is too long.
354354 # @raises [ProtocolError] if the line is not terminated properly.
355355 def read_line?
@@ -366,8 +366,9 @@ def read_line?
366366 end
367367
368368 return line
369-
370- # I considered rescuing Errno::ECONNRESET here, but it seems like that would be ignoring a potentially serious error.
369+ # If a connection is shut down abruptly, we treat it as EOF, but only specifically in `read_line?`.
370+ rescue Errno ::ECONNRESET
371+ return nil
371372 end
372373
373374 # Read a line from the connection.
Original file line number Diff line number Diff line change 33## Unreleased
44
55 - Tidy up implementation of ` read_line? ` to handle line length errors and protocol violations more clearly.
6+ - Improve error handling for unexpected connection closures (` Errno::ECONNRESET ` ) in ` read_line? ` .
67
78## v0.35.0
89
Original file line number Diff line number Diff line change 4848 server . read_line?
4949 end . to raise_exception ( Protocol ::HTTP1 ::ProtocolError )
5050 end
51+
52+ it "returns nil on Errno::ECONNRESET" do
53+ expect ( server . stream ) . to receive ( :gets ) . and_raise ( Errno ::ECONNRESET )
54+
55+ expect ( server . read_line? ) . to be_nil
56+ end
5157 end
5258
5359 with "#read_request" do
You can’t perform that action at this time.
0 commit comments