Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add IOBuffer to Client, remove from ThreadPool thread instances #3013

Merged
merged 1 commit into from
Nov 13, 2022

Conversation

MSP-Greg
Copy link
Member

@MSP-Greg MSP-Greg commented Nov 5, 2022

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 to str_headers in Request#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

  • I have reviewed the guidelines for contributing to this repository.
  • I have added (or updated) appropriate tests if this PR fixes a bug or adds a feature.
  • My pull request is 100 lines added/removed or less so that it can be easily reviewed.
  • If this PR doesn't need tests (docs change), I added [ci skip] to the title of the PR.
  • If this closes any issues, I have added "Closes #issue" to the PR description or my commit messages.
  • I have updated the documentation accordingly.
  • All new and existing tests passed, including Rubocop.

@MSP-Greg
Copy link
Member Author

MSP-Greg commented Nov 5, 2022

Actions CI is having issues. The only failed job didn't complete the setup-ruby step. See failed step. Today, I've seen the same in my repo forks...

Copy link
Member

@dentarg dentarg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me

@MSP-Greg MSP-Greg merged commit e0b86fe into puma:master Nov 13, 2022
@MSP-Greg MSP-Greg deleted the 00-io-buffer-2-client branch November 13, 2022 15:52
@MSP-Greg MSP-Greg added refactor and removed bug labels Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants