Skip to content

Commit 6e35f51

Browse files
committed
Extra debugging.
1 parent c0c63cb commit 6e35f51

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

examples/many/client.rb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: true
3+
4+
require 'async'
5+
require 'async/http/internet'
6+
7+
def get_responses_using_fibers(count)
8+
puts("Getting #{count} responses using fibers.")
9+
url = "https://httpbin.org/delay/0.001"
10+
responses = []
11+
12+
Async do
13+
puts("Starting Async block.")
14+
begin
15+
internet = Async::HTTP::Internet.new
16+
response_count = 0
17+
count.times do
18+
Async do
19+
begin
20+
response = internet.get(url)
21+
response_count += 1
22+
puts("Response count: #{response_count}. Received response: #{response.status}")
23+
responses << response.status
24+
rescue => e
25+
puts("Error during request: #{e.message}")
26+
# ensure
27+
# response&.finish
28+
end
29+
end
30+
end
31+
rescue => e
32+
puts("Error during outer: #{e.message}")
33+
ensure
34+
internet&.close
35+
end
36+
end.wait
37+
38+
puts("Ending Async block.")
39+
responses
40+
end
41+
42+
count = ARGV.first ? ARGV.first.to_i : 129
43+
get_responses_using_fibers(count)
44+
puts('Done.')

fixtures/async/http/a_protocol.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,23 @@ module HTTP
501501
with 'slow server' do
502502
let(:app) do
503503
::Protocol::HTTP::Middleware.for do |request|
504+
$stderr.puts "Sleeping for #{endpoint.timeout * 2} seconds..."
504505
sleep(endpoint.timeout * 2)
506+
$stderr.puts "Sending response..."
505507
::Protocol::HTTP::Response[200, {}, []]
506508
end
507509
end
508510

509511
it "can't get /" do
510512
expect do
511-
client.get("/")
513+
response = client.get("/")
514+
$stderr.puts "Response: #{response.inspect}"
515+
ensure
516+
$stderr.puts "Closing response..."
517+
response&.close
512518
end.to raise_exception(::IO::TimeoutError)
519+
520+
$stderr.puts "Test is done..."
513521
end
514522
end
515523

lib/async/http/protocol/http1/server.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ def each(task: Task.current)
6868
stream = write_upgrade_body(protocol)
6969

7070
# At this point, the request body is hijacked, so we don't want to call #finish below.
71-
request = response = nil
71+
request = nil unless request.body
72+
response = nil
7273

7374
body.call(stream)
7475
else
@@ -78,15 +79,17 @@ def each(task: Task.current)
7879
stream = write_tunnel_body(request.version)
7980

8081
# Same as above:
81-
request = response = nil
82+
request = nil unless request.body
83+
response = nil
8284

8385
body.call(stream)
8486
else
8587
head = request.head?
8688
version = request.version
8789

8890
# Same as above:
89-
request = response = nil
91+
request = nil unless request.body
92+
response = nil
9093

9194
write_body(version, body, head, trailer)
9295
end

lib/async/http/protocol/http2/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def call(request)
3535

3636
response = create_response
3737
response.send_request(request)
38+
$stderr.puts "Waiting for response..."
3839
response.wait
3940

4041
return response

lib/async/http/protocol/http2/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def closed(error)
123123

124124
@exception = error
125125

126-
notify!
126+
self.notify!
127127
end
128128
end
129129

0 commit comments

Comments
 (0)