Skip to content

Enforce write timeout when body_stream is used #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/net/http/generic_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,7 @@ def send_request_with_body_stream(sock, ver, path, f)
IO.copy_stream(f, chunker)
chunker.finish
else
# copy_stream can sendfile() to sock.io unless we use SSL.
# If sock.io is an SSLSocket, copy_stream will hit SSL_write()
IO.copy_stream(f, sock.io)
IO.copy_stream(f, sock)
end
end

Expand Down
28 changes: 28 additions & 0 deletions test/net/http/test_http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,34 @@ def test_timeout_during_HTTP_session_write
th&.join
end

def test_timeout_during_non_chunked_streamed_HTTP_session_write
th = nil
# listen for connections... but deliberately do not read
TCPServer.open('localhost', 0) {|server|
port = server.addr[1]

conn = Net::HTTP.new('localhost', port)
conn.write_timeout = 0.01
conn.read_timeout = 0.01 if windows?
conn.open_timeout = 0.1

req = Net::HTTP::Post.new('/')
data = "a"*50_000_000
req.content_length = data.size
req['Content-Type'] = 'application/x-www-form-urlencoded'
req.body_stream = StringIO.new(data)

th = Thread.new do
err = !windows? ? Net::WriteTimeout : Net::ReadTimeout
assert_raise(err) { conn.request(req) }
end
assert th.join(10)
}
ensure
th&.kill
th&.join
end

def test_timeout_during_HTTP_session
bug4246 = "expected the HTTP session to have timed out but have not. c.f. [ruby-core:34203]"

Expand Down