diff --git a/Cargo.lock b/Cargo.lock index ecc2af9..9111aca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1883,7 +1883,7 @@ dependencies = [ [[package]] name = "wreq" version = "0.16.1" -source = "git+https://github.com/0x676e67/wreq?rev=10029bb86ff88d8ed88b8e10518fe6e1f7ff322c#10029bb86ff88d8ed88b8e10518fe6e1f7ff322c" +source = "git+https://github.com/0x676e67/wreq?rev=18d500474139c6740c841d3263f82a7eb1ac4883#18d500474139c6740c841d3263f82a7eb1ac4883" dependencies = [ "btls", "btls-sys", diff --git a/Cargo.toml b/Cargo.toml index 3e89eda..930db11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -79,5 +79,5 @@ netty = { git = "https://github.com/0x676e67/netty", rev = "0e1e53c0d9e500b25336 btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" } btls-sys = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" } tokio-btls = { git = "https://github.com/0x676e67/btls", rev = "5ec1c113a03626a5877b34dd6d2ea8d440897a91" } -wreq = { git = "https://github.com/0x676e67/wreq", rev = "10029bb86ff88d8ed88b8e10518fe6e1f7ff322c" } +wreq = { git = "https://github.com/0x676e67/wreq", rev = "18d500474139c6740c841d3263f82a7eb1ac4883" } wreq-util = { path = "crates/wreq-util" } diff --git a/test/error_handling_test.rb b/test/error_handling_test.rb index e229dba..abee6f9 100644 --- a/test/error_handling_test.rb +++ b/test/error_handling_test.rb @@ -121,8 +121,47 @@ def test_proxy_error_handling end end + def test_proxy_tcp_connect_timeout_keeps_proxy_error + skip "Requires a stalled TCP handshake from a full loopback accept queue" unless RUBY_PLATFORM.include?("linux") || Gem.win_platform? + + with_stalled_tcp_listener do |port| + %w[http socks5h].each do |scheme| + client = Wreq::Client.new(proxy: "#{scheme}://127.0.0.1:#{port}", connect_timeout: 1, timeout: 5) + start = Process.clock_gettime(Process::CLOCK_MONOTONIC) + + error = assert_raises(Wreq::ProxyConnectionError, "#{scheme} proxy TCP deadline") do + client.get("https://127.0.0.1:443/") + end + assert_instance_of Wreq::ProxyConnectionError, error + assert_operator Process.clock_gettime(Process::CLOCK_MONOTONIC) - start, :>=, 0.9, + "#{scheme} proxy should time out, not fail immediately" + end + end + end + private + def with_stalled_tcp_listener + sockets = [] + listener = Socket.new(:INET, :STREAM) + listener.bind(Socket.sockaddr_in(0, "127.0.0.1")) + listener.listen(0) + address = listener.local_address + + # Leave the accept queue full and verify a subsequent dial stays pending. + pending = 8.times.any? do + socket = Socket.new(:INET, :STREAM) + sockets << socket + socket.connect_nonblock(address, exception: false) == :wait_writable && + IO.select(nil, [socket], nil, 0.2).nil? + end + assert pending, "Expected a stalled TCP handshake on the loopback fixture" + yield address.ip_port + ensure + sockets.each(&:close) + listener&.close + end + def with_hanging_server server = TCPServer.new("127.0.0.1", 0) accepted = Queue.new