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

Change HttpParserError to be subclass of StandardError #3590

Merged
merged 3 commits into from
Jan 1, 2025

Conversation

MSP-Greg
Copy link
Member

@MSP-Greg MSP-Greg commented Dec 30, 2024

Description

A long time ago (02-April-2006), HttpParserError was added, and it was a subclass of IOError. Today, IOError is more associated with errors at the IO level.

Puma should differentiate between socket level errors and HTTP request validity errors. Hence, change HttpParserError to be subclass of StandardError. This change will stop HttpParserError from being 'swallowed' in:

puma/lib/puma/client.rb

Lines 184 to 190 in f5e4b77

begin
if fast_check && @to_io.wait_readable(FAST_TRACK_KA_TIMEOUT)
return try_to_finish
end
rescue IOError
# swallow it
end

This PR also uncomments two tests in test/test_request_invalid.rb, which fail on master.

Note that @to_io.wait_readable may throw other socket related errors. Something to keep an eye on...

Closes #3552

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.

Sorry, something went wrong.

@github-actions github-actions bot added the waiting-for-review Waiting on review from anyone label Dec 30, 2024
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.

Sounds like the right thing to do

@github-actions github-actions bot added waiting-for-merge and removed waiting-for-review Waiting on review from anyone labels Dec 30, 2024
@MSP-Greg
Copy link
Member Author

@dentarg

Thanks for the quick review. I'll wait a little while to see if anyone else has comments.

As to a method to my madness (and three open PR's dealing with request error handling), this started with a realization that Puma wasn't properly closing invalid keep-alive requests, and leaving the parser with a buffer full of some or all of request 'A'.

After the error, since it was a keep-alive, the code in Server#handle_request then tried to see if another request was on the socket, and starts by parsing the buffer, which is part of request 'A'. Not pretty.

Then, I noticed that code that checked and/or modified the env was contained in both client.rb and request.rb (which is included in server.rb). That is confusing and also makes CI more involved. The reorg for that is in PR #3582... The code in the client tests is much simpler, I haven't yet written code to allow a 'test' request to be sent in more than one chunk with delays in between...

Copy link
Contributor

@joshuay03 joshuay03 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, nice one!

@MSP-Greg MSP-Greg merged commit 07ef55d into puma:master Jan 1, 2025
86 checks passed
@MSP-Greg MSP-Greg deleted the 00-change-parser-error branch January 1, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid request is swallowed and times out
3 participants