Skip to content

Commit 5fe1a48

Browse files
committed
Better error propagation.
1 parent 2d837fb commit 5fe1a48

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,35 @@ def call(request, task: Task.current)
5050
task.async(annotation: "Upgrading request...") do
5151
# If this fails, this connection will be closed.
5252
write_upgrade_body(protocol, body)
53+
rescue => error
54+
self.close(error)
5355
end
5456
elsif request.connect?
5557
task.async(annotation: "Tunnneling request...") do
5658
write_tunnel_body(@version, body)
59+
rescue => error
60+
self.close(error)
5761
end
5862
else
5963
task.async(annotation: "Streaming request...") do
6064
# Once we start writing the body, we can't recover if the request fails. That's because the body might be generated dynamically, streaming, etc.
6165
write_body(@version, body, false, trailer)
66+
rescue => error
67+
self.close(error)
6268
end
6369
end
6470
elsif protocol = request.protocol
6571
write_upgrade_body(protocol)
6672
else
67-
write_body(@version, body, false, trailer)
73+
write_body(@version, request.body, false, trailer)
6874
end
6975

7076
response = Response.read(self, request)
7177

7278
return response
73-
rescue
79+
rescue => error
7480
# This will ensure that #reusable? returns false.
75-
self.close
81+
self.close(error)
7682

7783
raise
7884
end

0 commit comments

Comments
 (0)