-
Notifications
You must be signed in to change notification settings - Fork 516
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
Limit Server::inBuf growth #1898
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,6 +146,9 @@ Server::doClientRead(const CommIoCbParams &io) | |
|
||
CommIoCbParams rd(this); // will be expanded with ReadNow results | ||
rd.conn = io.conn; | ||
Assure(Config.maxRequestBufferSize > inBuf.length()); | ||
rd.size = Config.maxRequestBufferSize - inBuf.length(); | ||
Comment on lines
+149
to
+150
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. Please be aware that FYI "0" is a special case. So, when this buffer contains 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.
maybeMakeSpaceAvailable() does not restrict capacity (enough): The method may increase capacity up to the specified maximum (if needed), but it does not shrink already excessive capacity.
Existing mayBufferMoreRequestBytes() check executed a few lines earlier makes the precondition in the above statement false -- this buffer cannot contain |
||
|
||
switch (Comm::ReadNow(rd, inBuf)) { | ||
case Comm::INPROGRESS: | ||
|
||
|
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.
FYI "0" is a special case. So, when this buffer contains
SQUID_TCP_SO_RCVBUF
bytes, the behaviour you are trying to avoid may occur despite this change.I believe the fix you actually want is to use
SBuf::reserve
to set the buffer limits properly (fixing the above TODO reservation and related lines). Then enforce the resulting space available. Like so: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.
Existing
Must(readBuf.length() < SQUID_TCP_SO_RCVBUF)
code executed a few lines earlier makes the precondition in the above statement false -- the buffer cannot containSQUID_TCP_SO_RCVBUF
bytes at this point.We have considered that approach and ruled it out: SBuf::reserve() is not the right solution for the problem targeted by this PR because SBuf::reserve() must not shrink existing SBuf capacity. In modern C++, both std::vector::reserve() and std::string::reserve() do not shrink the underlying storage. C++ folks even explicitly prohibited such shrinking for strings in C++20!
We could consider adding a dedicated buffer shrinking method, but since we already have a documented API for avoiding excessive reads (without buffer shrinking), and lack performance data to justify shrinking overheads, we should use that rd.size API to fix the problem.