-
Notifications
You must be signed in to change notification settings - Fork 22
Fix Net::ReadTimeout errors in net-pop by handling multi-byte terminators getting split up in readuntil #30
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
Open
astapinski
wants to merge
4
commits into
ruby:master
Choose a base branch
from
HiMamaInc:fix/readuntil_offset/astapinski
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+24
−1
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eac2c7e
Set offset for terminator searching to use the terminator bytesize
cc58835
Tweak the readuntil offset logic
5d63ff1
Add a test for multi-byte terminators in each_message_chunk and readu…
5f887c1
Replace each_message_chunk calculation with BUFSIZE
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,26 @@ def test_each_crlf_line | |
| end | ||
| end | ||
|
|
||
| def test_each_message_chunk_boundary | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test will fail if one uses the old logic for |
||
| assert_output("", "") do | ||
| # Create this first chunk where the chunk will end with the | ||
| # line terminator \r\n only being partially read up to and including \r. | ||
| chunk_1 = "#{"1" * (Net::BufferedIO::BUFSIZE - 1)}\r\n".b | ||
| chunk_2 = "Second line\r\n".b | ||
| chunk_3 = "Third line\r\n".b | ||
| test_string = "#{chunk_1}#{chunk_2}#{chunk_3}".b | ||
| sio = StringIO.new("#{test_string}.\r\n".b) | ||
| io = Net::InternetMessageIO.new(sio) | ||
| expected_chunks = [] | ||
| io.each_message_chunk do |chunk| | ||
| expected_chunks << chunk | ||
| end | ||
| assert_equal chunk_1, expected_chunks[0] | ||
| assert_equal chunk_2, expected_chunks[1] | ||
| assert_equal chunk_3, expected_chunks[2] | ||
| end | ||
| end | ||
|
|
||
| def create_mockio(capacity: 100, max: nil) | ||
| mockio = Object.new | ||
| mockio.instance_variable_set(:@str, +'') | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix here was to just set the offset in a way that it should only be set far enough ahead that a multiple byte terminator would still be read completely on the next read. For the comment, I'm not honestly sure if an empty buffer could be an issue but I played it safe and checked that new_offset is greater than offset before setting it.