diff --git a/gems/connectrpc-falcon/soak/http1_soak.rb b/gems/connectrpc-falcon/soak/http1_soak.rb index 0e32b92a..7eb79dda 100644 --- a/gems/connectrpc-falcon/soak/http1_soak.rb +++ b/gems/connectrpc-falcon/soak/http1_soak.rb @@ -11,6 +11,25 @@ def connect_head(method, length, id, action, extra = "") "Content-Length: #{length}\r\n#{Soak::Ledger::ID}: #{id}\r\n#{Soak::Topology::OP}: #{action}\r\n#{extra}\r\n" end + # Sends a client-stream head declaring `length` bytes but only its first + # message, then expects the reply and the connection's close within the + # settle bound, without ever sending the rest. + def withhold(campaign, origin, length, extra = "") + id = campaign.ledger.next_id("withheld-upload") + wire = ConnectH1Wire.new(origin) + campaign.track(:io, wire.raw, "withholding client socket") + wire.write(connect_head(Soak::Topology::CS, length, id, "first", extra) + envelope("first")) + campaign.task.with_timeout(Soak::SETTLE_SECONDS) do + status, = wire.head + expect(status).to eq(200) + # The echoed message, then an end-stream without an error. + expect(wire.body).to eq("#{envelope('first')}#{[2, 15].pack('CN')}{\"metadata\":{}}") + expect(wire.socket.read).to eq("") + end + expect(Soak.poll("withheld upload handler end") { campaign.ledger.ended(id) }).to eq(:ok) + wire.close + end + def unread(socket) buffer = [0].pack("i") socket.ioctl(Soak::RawH2::FIONREAD, buffer) @@ -42,7 +61,8 @@ def unread(socket) it "5 slow peers (HTTP/1.1): withheld upload retires within the input bounds; a never-reading client is " \ "bounded by close grace" do - campaign("5-slow-peers-http1/falcon", workload: "early Connect reply to a withheld 100 KB upload; 20 MB " \ + campaign("5-slow-peers-http1/falcon", workload: "withheld 100 KB upload read until its deadline and " \ + "withheld 1 MB upload answered at once; 20 MB " \ "server stream to a client that never reads", concurrency: 2, payload_sizes: [16, Soak::Topology::FLOOD_MESSAGE]) do |c| peer = c.peer_thread("falcon servers") @@ -50,17 +70,14 @@ def unread(socket) clients = c.http1(server.origin, label: "persistent http1", persistent: true, reuse: true) c.run do c.perform(clients, :unary) - withheld = c.ledger.next_id("withheld-upload") - wire = ConnectH1Wire.new(server.origin) - c.track(:io, wire.raw, "withholding client socket") - wire.write(connect_head(Soak::Topology::CS, 100_000, withheld, "first") + envelope("first")) - status, = wire.head - expect(status).to eq(200) - wire.body - eof = c.task.with_timeout(5) { wire.socket.read } - expect(eof).to eq("") - expect(Soak.poll("withheld upload handler end") { c.ledger.ended(withheld) }).to eq(:ok) - wire.close + # Falcon reads a declared remainder under 256 KiB before its reply, so + # the Connect deadline bounds this one. Without it the default 60 s + # request_body_timeout would hold the reply for 60 s, long enough for + # the server's independent 60 s idle_timeout to retire the persistent + # client's idle connection. A remainder of 256 KiB or more is left + # unread and answered at once. + withhold(c, server.origin, 100_000, "Connect-Timeout-Ms: #{Soak::TIMER_HEADROOM * 1000}\r\n") + withhold(c, server.origin, 1_000_000) Soak::Builders::H1_SHAPES.each { |shape| c.perform(clients, shape) } doomed = c.server(peer, kind: :falcon, persistent: false, label: "falcon non-reading target")