Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
39 changes: 39 additions & 0 deletions test/error_handling_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading