mirror of
https://github.com/ruby/ruby.git
synced 2025-09-21 19:44:01 +02:00
[ruby/net-http] Enforce write timeout when body_stream is used
The existing implementation of `Net::HTTP#write_timeout` relies on
`Net::BefferedIO` to trigger the `Net::WriteTimeout` error. This commit
changes `send_request_with_body_stream` to remove the optimization that
was making `Net::HTTP#write_timeout` not work when `body_stream` is
used.
Open issue:
https://bugs.ruby-lang.org/issues/17933
a0fab1ab52
This commit is contained in:
parent
b3413914d9
commit
60b02db516
2 changed files with 29 additions and 3 deletions
|
@ -576,6 +576,34 @@ module TestNetHTTP_version_1_1_methods
|
|||
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]"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue