Skip to content

Commit fe9fcc4

Browse files
authored
Fix handling of request bodies in HTTP/1 server loop. (#138)
1. Fixes an old regression where request = nil should be conditional upon the request body, but was incorrectly the response body. Looking at the git history, the original behavior was ... unless request.body and was changed in b3cc9ce, seemingly accidentally during a refactor. I occasionally experience random hangs when running my test suite and believe this might be one cause of them. 2. Changes the handling of unconsumed bodies from request.finish to request.each{}. finish buffers the request fully in memory as a Buffered, causing needless memory bloat in the ruby process. Using each skips the buffering, but is otherwise behaves the same.
1 parent 789983a commit fe9fcc4

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def each(task: Task.current)
8383
version = request.version
8484

8585
# Same as above:
86-
request = nil unless body
86+
request = nil unless request.body
8787
response = nil
8888

8989
write_body(version, body, head, trailer)
@@ -98,7 +98,7 @@ def each(task: Task.current)
9898
end
9999

100100
# Gracefully finish reading the request body if it was not already done so.
101-
request&.finish
101+
request&.each{}
102102

103103
# This ensures we yield at least once every iteration of the loop and allow other fibers to execute.
104104
task.yield
@@ -109,6 +109,7 @@ def each(task: Task.current)
109109
end
110110
end
111111
end
112+
112113
end
113114
end
114115
end

0 commit comments

Comments
 (0)