Project

General

Profile

Actions

Bug #17933

closed

`Net::HTTP#write_timeout` doesn't work with `body_stream`

Added by miguelfteixeira (Miguel Teixeira) almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
[ruby-core:104124]

Description

While testing Net::HTTP#write_timeout using the server example from the Feature Issue, I've noticed that Faraday multipart requests (with a file parameter) didn't trigger WriteTimeout. The root cause is that Net::HTTPGenericRequest#send_request_with_body_stream is not using Net::BufferedIO (the class that implements the write timeout).

The following patch fixes the issue, but looking at the comments, it's unclear if it will break some existing functionality. Albeit all the tests pass.

--- a/lib/net/http/generic_request.rb
+++ b/lib/net/http/generic_request.rb
@@ -204,7 +204,7 @@ def send_request_with_body_stream(sock, ver, path, f)
     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
➜  ruby git:(fix-net-http-write-timeout-body-stream) ✗ ../mspec/bin/mspec run library/net/
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]
[- | ==================100%================== | 00:00:00]      0F      0E

Finished in 2.029623 seconds

187 files, 876 examples, 1214 expectations, 0 failures, 0 errors, 0 tagged

Any thoughts on this? It looks like Net::HTTP#write_timeout is partially implemented, and we should ensure that it either works on all use cases or an error is raised when it's used in a non-supported use case.

I'm more than happy to help with the implementation. If this patch is the correct approach, I can also create new unit tests to assert the proper behaviour.


Related issues 1 (1 open0 closed)

Related to Ruby master - Feature #18228: Add a `timeout` option to `IO.copy_stream`OpenActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0