Skip to content

Commit

Permalink
Stop writing after receiving Errno::EPIPE
Browse files Browse the repository at this point in the history
We want to stop writing after server has closed its end of the pipe (as
no more data will be accepted) and proceed with reading the response.
  • Loading branch information
janko committed May 23, 2018
1 parent 7aa3e43 commit 8529ffa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Layout/SpaceAroundOperators:
Layout/SpaceInsideHashLiteralBraces:
EnforcedStyle: no_space

## Lint ########################################################################

Lint/HandleExceptions:
Enabled: false

## Metrics #####################################################################

Metrics/AbcSize:
Expand Down
4 changes: 3 additions & 1 deletion lib/http/request/writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def send_request
write(data) unless data.empty?

write(CHUNKED_END) if chunked?
rescue Errno::EPIPE
# server doesn't need any more data
end

# Returns the chunk encoded for to the specified "Transfer-Encoding" header.
Expand All @@ -101,7 +103,7 @@ def write(data)
data = data.byteslice(length..-1)
end
rescue Errno::EPIPE
# server doesn't need any more data
raise # re-raise Errno::EPIPE
rescue IOError, SocketError, SystemCallError => ex
raise ConnectionError, "error writing to socket: #{ex}", ex.backtrace
end
Expand Down

0 comments on commit 8529ffa

Please sign in to comment.