Add IOBuffer to Client, remove from ThreadPool thread instances #3013
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, an IOBuffer object is created in each thread in each ThreadPool (one per worker). This object is used to assemble response headers, and also may contain parts or all of the response body.
It is shared among all clients/connections processed in the thread. The data is cleared after every request. But, given all the code paths, etc, if it was not cleared, it could leak headers between responses from different clients.
No one has reported this occurring. Regardless, it is a relatively lightweight object subclassed from StringIO (a default gem in Ruby), so rather than share an instance with clients in a thread, remove it from the thread, and add it to the Client class. Doing so makes it impossible for data to go to the wrong client.
Also, this allows changing/simplifying some method signatures. Previously, there was a calculation in
Request#str_headers
that calculated whether to force a 'keep-alive' connection closed. Moved the calculation to immediately before the call tostr_headers
inRequest#prepare_response
. The calcuation is time sensitive, but there are no 'blocking' operations preceding the code using the calculation result.Lastly, as improvements to Ruby and/or Puma allow more concurrency, this extra isolation may be needed in the future.
Moving IOBuffer has been discussed somewhere, don't recall when/where...
Your checklist for this pull request
[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.