Repository navigation
Find ReadUntil delimiter split between reads - #142
Merged
Merged
Conversation
Owner
Author
|
Independent review of head Checked:
P3:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
TByteReader::ReadUntilsearched for the delimiter only in the internal buffer and, before every new read, moved the whole buffer into the result. A delimiter split between two reads (TCP segmentation, or crossing the 1024-byte boundary of the temporary read buffer) was therefore never found, and the coroutine kept waiting for data that had already arrived. The HTTP server reads request headers withReadUntil("\r\n\r\n")and chunk headers withReadUntil("\r\n"), so such requests hung until the peer (e.g. nginx) gave up.Fix
Data stays in the buffer and the search resumes from
size - (delimiter.size() - 1)after each read, so a split delimiter is found without rescanning the accumulated data. The returned value is unchanged (everything up to and including the delimiter); bytes after it stay buffered. An empty delimiter returns an empty string (documented).Other readers checked:
TLineReader,TLineSplitter,TZeroCopyLineSplitter(single-byte delimiter, cannot be split),ws.hpp(only callsReadUntil),httpd(only callsReadUntil); no other occurrence of the pattern.Tests
In
tests/test_http.cpp: delimiter split at every position, one byte per read, delimiter crossing the 1024-byte boundary, two consecutive delimiters, and an end-to-endTWebServerrequest whose header is split between two writes. All of them fail on master (missed delimiter reported as closed connection, or a 5 s deadline in the server test) and pass with the fix.The free-port helper used by the tests is now
NNet::GetFreePort()incoroio/address.hpp(it replacesgetport()intests/tests.cppand is used by the new server test).